Home > Back-end >  Big help check
Big help check

Time:06-11

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])

CodePudding user response:

reference 1st floor SuperDay response:
sizeof (a) behind don't divided by sizeof (a [0])

That said is the number of the digital array, remove the bytes is the beep

CodePudding user response:

Number is right, as long as the number is enough, think it over

CodePudding user response:

reference SuperDay reply: 3/f
number is right, as long as the number is enough, to think about

Still won't do I think you the problem of near printf, because no matter how will give ret assignment and returned to the loc beep  but now nothing output, bosses think I printf nearby if you have any questions?

CodePudding user response:

The scanf format inside don't use a newline, what all need not add

CodePudding user response:

reference 5 floor SuperDay reply:
the scanf format inside don't use a newline, what all need not add

That's it! Thank you big! To solve the

CodePudding user response:


I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related