The if statement is used to route program execution through two different paths. The if statement is the most basic of all the control flow statements. It tells your program to execute a certain section of code only if a particular test evaluates to true. The if statement is written with the if keyword, followed by a condition in parentheses, with the code to be executed in between curly brackets.
Syntax :
If ( condition )
{
// block of statement to be executed if condition is true ;
}
The program is a C++ program to find the greatest of two numbers. Firstly, the program declares two integer variables 'a' and 'b'. The user is prompted to enter the values of 'a' and 'b' using the 'cin' function. The values of 'a' and 'b' are then stored in their respective variables.
The program then checks the values of 'a' and 'b' using the 'if' condition. If 'a' is greater than 'b', then it displays a message stating that 'a' is the greatest number using the 'cout' statement. If 'b' is greater than 'a', then it displays a message stating that 'b' is the greatest number using the 'cout' statement. If 'a' and 'b' are equal, then it displays a message stating that 'a' and 'b' are equal using the 'cout' statement. Finally, the program returns 0, which indicates that the program has executed successfully.
#include<iostream> using namespace std; int main() { int a,b; cout<<"\nEnter The Value of A & b :"; cin>>a>>b;//25,45 if(a>b)//25>45 { cout<<a<<" is Greatest Number"; } if(b>a)//45>25 { cout<<b<<" is Greatest Number"; } if(a==b)//45==25 { cout<<a<<" and "<<b<<" are Equal"; } return 0; }
Enter The Value of A & b :23 56 56 is Greatest NumberTo download raw file Click Here
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions