Hello Everyone,
How can i write a programme in c which finds the biggest integer in the array without using any loop.........
Hello Everyone,
How can i write a programme in c which finds the biggest integer in the array without using any loop.........
use recursion
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.
well i thought he ment loop as a syntax concept, but i agree with you, its impossible to compare the elements of array without a loop
Thank You for your reply........
No. A whole whack of nested ifs should do... as long as you know the size of the array and it's fixed.
Code:{ int i=1, L, big; //find length of arrray in any int variable. //then //if u dont want to use recursive() , use goto statement //do this big= array[0]; lable: if(L<len) //len is length of array { if(big<array[i]) big=array[i]; i++, L++; goto lable; } //use printf here with big variable getch(); } //try it , i haven' t tried yet.
A couple of advices for you. Here is probably what you should fix in your code:
1) Indentation is lacking.
2) Use of goto should be gotten rid of (use loops).
Also:
It's bad to hand out solutions to people, because often they will learn much more if they are guided into making the right code.
gurpreet is right though: goto is another way to avoid using loops, though arguably all that happens is that the goto simulates a loop, but the same can be said of recursion, especially tail recursion.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Code:int biggest(int *array, int len) { int big; if(len == 1) return *array; big = biggest(array + 1, len - 1); return (array[0] > big) ? array[0] : big; }
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}