how to find the maximum of 10 numbers ?

Answer Posted / ahmed.aboelella

/**
As there is no need to save in array
Also we have to init max with first value to get max in case
user entered negative values
*/

#include "iostream"

using namespace std;

void main()
{
cout<<"Enter 10 numbers: ";

int i, temp, max;

//Enter first number to init max
cin>>max;

for(i = 0 ; i < 9; i ++)
{
cout<<"Enter Number: ";
cin>>temp;
max = temp > max ? temp : max;
}

cout<<"Max Number is "<<max<<endl;

}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What operators can you overload in c++?

675


What do manipulators do?

665


State the difference between pre and post increment/decrement operations.

702


How to declare an array of pointers to integer?

688


What is the best way to declare and define global variables?

825






What is a pdb file?

634


Can we define a constructor as virtual in c++?

689


Explain stack unwinding.

731


What is c++ virtual inheritance?

691


What is the most useful programming language?

693


Comment on c++ standard exceptions?

728


Which is the best c++ software?

706


Explain the uses oof nested class?

717


Can member data be public?

689


What does 7/9*9 equal ? a) 1 b) 0.08642 c) 0

666