Re: finding second maximumin array

Posted 15 January 2009 - 04:14 AM

stefan.jacobs, on 15 Jan, 2009 - 02:59 AM, said:

What seems to be the problem ?

my programme finding the second maximum, but the way is not good.
i had to do that in recursive way and not with recursia that very similar to for loop...
i should over the array just once, so i cant find the maximum and then drop it and find the new maximum...

And ofc you need to make you main() function an int, and put in a return 0; at the end of it.
And this is because main should always be declared an int.
It may be that some compilers allow otherwise and might even change it to an int with a return statement at the end without you ever having to worry about it.
But you should always make your main like this:

int main(){
return 0;
}
// This is also an approach if you want it to be able to take runtime arguments
int main( int argc, char *argv[] ){
return 0;
}

EDIT: You should also change <iostream.h> to just <iostream> and also toss in a 'using namespace std' on the next line under it.
And it is also good to try to avoid using global variables.

And ofc you need to make you main() function an int, and put in a return 0; at the end of it.
And this is because main should always be declared an int.
It may be that some compilers allow otherwise and might even change it to an int with a return statement at the end without you ever having to worry about it.
But you should always make your main like this:

int main(){
return 0;
}
// This is also an approach if you want it to be able to take runtime arguments
int main( int argc, char *argv[] ){
return 0;
}

EDIT: You should also change <iostream.h> to just <iostream> and also toss in a 'using namespace std' on the next line under it.
And it is also good to try to avoid using global variables.

its not good.
because i can loss solution.
for exemple if max2>max1
but anyway its not good.
i have to do it in recursive way..
and not with tail recursive...
tail recursive means that it very similar to for loop.