if-else is a technique used in programming. It is having a common syntax in most of the programming languages like C, C++, java etc. Its logic is quite simple.
Take a look on the flowchart to understand the logic.
The syntax of if-else statement is
if(condn)
{
stmt1;
}
else
{
stmt2;
}
stmt1 is executed if the condition given in the f statement is satisfied otherwise stmt2 is executed.
Example Program
Program to check whether the number given is prime or not.
#include<iostream.h>
void main()
{
int no;
cout<<"Enter the number :";
cin>>no;
if(no%2==0)
{
cout<<"\n Number is even";
}
else
{
cout<<"\n Number is odd";
}
}
No comments :
Post a Comment