![]() |
Can you find bug??
This program is goin infinite loop....
Code: c
|
Re: Can you find bug??
your loop is goin infinite because of your array index overflowed.
when the loop = 0, InpArray[loop] = InpArray[0] = 1,then the if-clause returned true so 1 changed to -1,that's the problem,the c language never check the array index. |
Re: Can you find bug??
try defining this above your array and you will some other error.
int nSum=0,loop,missingNum; |
Re: Can you find bug??
You're problem is that you are accessing an array with a negative subscript. This
accidentally modifies your loop variable, unless as shabbir noted, you move the array declaration to after the other variables. But of course this still leaves the problem of negative array indicies. If you "play computer" for just 2 iterations of the loop, you will see how you get the negative index. If you're just trying to find the missing number (presumably 5 in this case) then try this instead: * Set up another array of SIZE elements called Seen, initialized to 0. * Loop through InpArray and set the corresponding Seen element to 1. * Then loop through Seen and print out the element number of any zeroes you find. |
| All times are GMT +5.5. The time now is 05:37. |