In: Computer Science
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)
#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); } }