Tuesday, November 20, 2012

C++: Maximum of three numbers(function)

#include<iostream.h>
int max(int x,int y ,int z)
{
            if(x>y&&x>z) return x;
            else if (y>x&&y>z)return y;
            else if (z>x&&z>y)return z;
}
int main()
{
            int x,y,z,m;
cout<<"enter x"<<endl;cin>>x;
cout<<"enter y"<<endl;cin>>y;
cout<<"enter z"<<endl;cin>>z;
m=max(x,y,z);
cout<<"Max is"<<m;
return 0;
}

No comments:

Post a Comment