I tried an array is combined with function calls a procedure, function is to define an array a []={2,3,4,5,6,7,8,9,}, and then I input a number of the array, such as "5", it can tell me the number of locations, such as "5" position is 3 now, I checked several times my code shouldn't be a problem, but he couldn't output, but also in the big trouble, please help me to check the code have what problem
#include Int search (int key, int a [], int length) { Int ret=1; int i; for(i=0; i{ If (a==[I] key) { Ret=I; break; } } Return ret. }
Int main () { int x; Int a []=,3,4,5,6,7,8,9,10 {2}; Int loc; Printf (" please enter a number: "); The scanf (" % d \ n ", & amp; X); Loc=search (x, a, sizeof (a)/sizeof (a [0])); If (loc!=1) {
Printf (" in the position of % d % d ", x, loc); } else {
Printf (" can't find this number "); } return 0; }
CodePudding user response:
Behind the sizeof (a) don't divided by sizeof (a [0])