Thursday, October 16, 2014

Nested if-else in c++




Prog 7: Write a program to find max. value from three values by using nested if-else.
  #include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
cout<<"enter the value of a:";
cin>>a;
cout<<"enter the value of b:";
cin>>b;
cout<<"enter the value of c:";
cin>>c;
if(a>b)
{


        if(a>c)
         cout<<"a is max.";
         else
         cout<<"c is max.";
 
}
else
{
         if(b>c)
         cout<<"b is max.";
          else
        cout<<"c is max.";
  }


getch();
}

Output:

enter the value of a:11 enter the value of b:12 enter the value of c:13 c is max.
 

No comments: