Question

In: Computer Science

Write a complete C program that searches an element in array using pointers. Please use the...

Write a complete C program that searches an element in array using pointers. Please use the function called search to find the given number.

//Function Prototype void search (int * array, int num, int size)

Solutions

Expert Solution

#include <stdio.h>

void search (int * array, int num, int size){
    int found = 1;
    int* p;
    for(p = array; p<(array+size); p++){
        if(*p == num){
            found = 1;
            break;
        }
    }
    if(found==1){
        printf("%d found in the array\n",num);
    }
    else{
        printf("%d is not found in the array\n",num);
    }
}

int main()
{
    int data[] = {4,2,3,1,6,5};
    search(data, 1, 6);
    return 0;
}

void search (int * array, int num, int size){
    int found = 1;
    int* p;
    for(p = array; p<(array+size); p++){
        if(*p == num){
            found = 1;
            break;
        }
    }
    if(found==1){
        printf("%d found in the array\n",num);
    }
    else{
        printf("%d is not found in the array\n",num);
    }
}

Related Solutions

write a program using the main method where it searches through an array of positive, non-zero...
write a program using the main method where it searches through an array of positive, non-zero integer values and prints out the maximum even and odd values. The program should use the array provided in the code, and you may assume that it has already been populated with values. The results should be printed out to the console in the following format: “Max Even: ”<<max even value>> “Max Odd: ”<<max odd value>> Values denoted in “<< >>” represent variable values,...
*C PROGRAMMING LANGUAGE* a) Given an array of size n, sort the array using pointers using...
*C PROGRAMMING LANGUAGE* a) Given an array of size n, sort the array using pointers using malloc or calloc. Examples: Input: n = 5, A= {33,21,2,55,4} Output: {2,4,21,33,55} b) Write a function that declares an array of 256 doubles and initializes each element in the array to have a value equal to half of the index of that element. That is, the value at index 0 should be 0.0, the value at index 1 should be 0.5, the value at...
Please, write code in c++. Using iostream and cstring library Use pointers! You given a text.Your...
Please, write code in c++. Using iostream and cstring library Use pointers! You given a text.Your task is to write a function that will find the longest sequence of digits inside. Note that the output have to be presened just like in sample. Note. The program have to use pointer. Input: First line contains one line that is not longer than 1000. Output: The longest sequence of numbers.All numbers are positive and integers. Samples: № INPUT OUTPUT 1 This is...
Please complete the following functions in "queue.c" using C. This must use the dynamic array provided...
Please complete the following functions in "queue.c" using C. This must use the dynamic array provided in "dynarray.c" -------------------------------------------------------------------------------------------- //queue.c #include <stdlib.h> #include "queue.h" #include "dynarray.h" /* * This is the structure that will be used to represent a queue. This * structure specifically contains a single field representing a dynamic array * that should be used as the underlying data storage for the queue. * * You should not modify this structure. */ struct queue { struct dynarray* array;...
Given the following array, write a program in C++ to sort the array using a selection...
Given the following array, write a program in C++ to sort the array using a selection sort and display the number of scores that are less than 500 and those greater than 500. Scores[0] = 198 Scores[3] = 85 Scores[6] = 73 Scores[9] = 989 Scores[1] = 486 Scores[4] = 216 Scores[7] = 319 Scores[2] = 651 Scores[5] = 912 Scores[8] = 846
Write a program in MIPS to find the largest element of an array, the array size...
Write a program in MIPS to find the largest element of an array, the array size should be less than or equal to 10. Has to be extremely basic, cannot use stuff like move. Very basic. Here is what I already have and I am stuck. .data myarray: .word 0,0,0,0,0,0,0,0,0,0 invalid: .asciiz "Number is invalid, store a number in the array that is from 0-10.\n" large: .asciiz "The largest element is " colon: .asciiz " :\t" enter: .asciiz "Store a...
Write a c++ member function that sequentially searches for a specific element in a doubly linked...
Write a c++ member function that sequentially searches for a specific element in a doubly linked list. return the position if found or -1 is the element cannot be found.
this program is to be done in c language. Using Pointers Create a program pointerTester.c to...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to experiment with pointers. Implement the following steps one by one in your program: YOU NEED TO ANSWER QUESTION Use printf to print your answers at the end(after 12). 1. Declare three integer variables a, b and c. Initialize them to 0, 100 and 225, respectively. 2. Print the value of each variable and its address. 3. Add the following declaration to your code: int...
C++ Write the code to implement a complete binary heap using an array ( Not a...
C++ Write the code to implement a complete binary heap using an array ( Not a vector ). Code for Max heap. Implement: AddElement, GetMax, HeapSort, ShuffleUp, ShuffleDown, etc Set array size to 31 possible integers. Add 15 elements 1,3,27,22,18,4,11,26,42,19,6,2,15,16,13 Have a default constructor that initializes the array to zeros.. The data in the heap will be double datatype. PART 2 Convert to the program to a template, test with integers, double and char please provide screenshots thank you so...
Write a program on C defining an array. Find the element at given index k. Replace the element at given index k.
Write a program on C defining an array. Find the element at given index k. Replace the element at given index k.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT