Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - C language realizes the function of finding the specified element in integer array?
C language realizes the function of finding the specified element in integer array?
# include & ltstdio.h & gt

int search(int a[],int n,int searchValue) {

int I;

for(I = 0; I & ltn;; I++) if(a[i]==searchValue) returns I;

return- 1;

}

int main() {

int I;

int a[ 10],find,idx

for(I = 0; I< 10; i++) {

printf("Input a[%d]:",I);

scanf("%d ",& ampa[I]);

}

printf(" Input search value:");

Scanf("%d ",& find);

idx=search(a, 10,find);

If (idx! =- 1) printf("pos=%d ",idx);

Else printf ("not found");

}