work with this: we need to assign "maximum" an initial minimum value but we cant use Min_value. so next best option is to compare the first two input values after the initial N value and assign the greater out of them to "maximum" now initial input N has to be >0. so rest everything will go inside an "if N>0" inside that if N=1 then read that number and assign it to "maximum" and print it. else N has to be at least 2 or more. so compare the two input numbers and assign the greater out of two to "maximum" now all comes down to the for loop. for(int a=0; a<(N-2); a++) notice (N-2). that's because at this point you have already used the first two inputs. so if N was only 2 then the loop wont initiate. if lets say there are 5 inputs then the loop will go for 3 times for the remaining three inputs which you can compare and assign a value to "maximum" accordingly. After the loop just print the "maximum".
A more complicated solution (if you dont know about Min_Value)
You must be signed in to leave a comment
19 May 2020, 06:51
If you use the MIN_- and MAX_VALUE constants, you can do everything in one loop. If not, you read all input into an array and then you set the var that should contain the result to the first array field and start your loop with index 1.Or you initialize the maximum var with one input (can also be done inside the loop), then you start a loop and compare against it. No need for an array and just one loop needed. Code not tested, therefore no guarantee :)
3 May 2020, 17:45
Does your program works well?