Code: //prompt the user to enter three numbers and find the greatest of them #include <iostream> using namespace std; int maximum(int, int, int); int main() { int a,b,c; cout<<"Enter three numbers "; cin>>a>>b>>c; cout<<"The largest number is "<<maximum( a, b, c); return 0; } int maximum( int x, int y, int z) { int max = x; if(y > max) max = y; if( z > max) max = z; return max; }
Code: #include<iostream.h> class max{ public: void get(int [],int); int sh(int [],int); }; void max::get(int *a,int b) { for(int i=0;i<b;i++) cin>> a[i]; } //------------ void max::sh(int *a,int b) { int mx=a[0]; for(int i=1;i<b;i++) if(a[i]>mx) mx=a[i]; return mx; } //------------ void main() { max j; int x[3]; j.get(x,3); int m=j.sh(x,3); cout<<" \n MAX = "<<m; }
Code: #include <iostream> using namespace std; int main() { int a=12,b=57; int greaterNum=0; greaterNum=(a>b)?a:b; cout<<'a='<<a<<endl <<'b='<<b<<endl <<"greaterNum='<<greaterNum<<endl; return 0; }