1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
// find the greates number in five
// cpp forum
#include<iostream>
using namespace std;
int findGreatest(int, int, int, int, int);
int main(){
int a,b,c,d,e;
cout << "enter five numbers: ";
cin >> a >> b >> c >> d >> e;
cout << "the greatest of all: ";
cout << findGreatest(a,b,c,d,e) << endl;
return 0;
}
int findGreatest(int a, int b, int c, int d, int e){
int greatest = 0;
if (a>b) greatest=a;
else greatest=b;
if (c>d && c > greatest)
greatest = c;
//else greatest is already greatest
else if (d > greatest) //d is bigger
greatest = d;
if (e > greatest) // processed a,b,c,d; now e.
greatest = e;
return greatest;
}
/*
enter five numbers: 22 33 44 55 11
the greatest of all: 55
enter five numbers: 1 2 3 4 5
the greatest of all: 5
enter five numbers: 345 66 33 5 999
the greatest of all: 999
enter five numbers: 999 2 3 4 555
the greatest of all: 999
*/
|