Tuesday, July 1, 2014

To find largest in two/three no.s

To find largest in two no.s

#include <iostream.h>
#include <conio.h>
void main ()
{
int a,b;
clrscr ();
cout <<"Enter A: ";
cin >>a;
cout <<"Enter B: ";
cin >>b;
if (a>b)
{
cout <<"A is Greater";
}
else
{
cout <<"B is Greater";
}
getch ();
}

To find largest in three no.s

#include <iostream.h>
#include <conio.h>
void main ()
{

 int a,b,c;
 cout<<"Enter three no.s:";
 cin>>a>>b>>c;
 if(a>b)
 {
  if(a>c)
   cout<<a<<"is greater";
  else
   cout<<c<<"is greater";
 }
 else
 {
  if(b>c)
   cout<<b<<"is greater";
  else
   cout<<c<<"is greater";
 }
getch();
}

No comments:

Post a Comment