+ 2
how can to compare three no. and tell which one is greater
3 Antworten
+ 2
not using if and else
#include <iostream. h>
#include <conio. h>
void main ()
{
int a,b,c;
cout<<"enter any three no.s "<<endl;
cin>>a>>b>>c;
a=(a>b)?a:b;c=(c>a)?c:a;
cout <<"/ngreater no is/t"<<c;
gatch ();
}
0
using if and AND
#include <iostream.h>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter first number"<<endl;
cin>>a;
cout<<"Enter second number"<<endl;
cin>>b;
cout<<"Enter third number"<<endl;
cin>>c;
if (a>b && a>c)
{
cout<<"A is greatest";
}
else if (b>a && b>c)
{
cout<<"B is greatest";
}
else if (c>a && c>b)
{
cout<<"C is greatest";
}
else cout<<"Either they are equal or non numeric";
}
I think this is it. if it is wrong someone might correct me since there wont be much to write .
Good luck and have fun coding!
0
thanks