Jan 7, 2012

Program : To Accept 5 Integer and Print Larger one

 Program : To Accept 5 Integer and Print Larger one using if statement

In this program i use if statement to check the largest no.
check the program:



#include<iostream.h>
#include<conio.h>
//Accept 5 Integer and Print Larger one
int main()
{
int a,b,c,d,e,f;
cout << "Enter Five Number\n";
cin >> a >> b >> c >> d >>e; //it take 5 no one after one
//let f is maximum no. & set that no. to be a variable
f =a;
//we assume a is max and then we set the condition with if
// statement and it will swap f value to largest one let chek it out
if(b>f)
f =b;
if(c>f)
f=c;
if(d>f)
f=d;
if(e>f)
f=e;
/*
In this  i set 4 condition and u see every condition give i didnt give any braces
because when we write without braces then it autoatc consider its scope
that next line to that condition only
like in every four condition aboce the scope of
assigning value is till there only one line

and above condition replace no according to condition true
that no greater than f
Its simple using if statement
*/
cout << "Largest No is " << f;

    getch();
    return 0;
}


OUTPUT


0 comments:

Post a Comment