if else block

If test condition is true, statements inside the body of if block will be executed otherwise statements inside the body of else block are executed.
यदि टेस्ट कंडीशन सत्य होती है तब if ब्लॉक के स्टेटमेंट रन किये जायेंगे अन्यथा else ब्लॉक के स्टेटमेंट रन किये जायेंगे।

Syntax:-
if(condition) statement;
else statement;

if(condition){
statements;
}
else{
statements;
}

Example:-
C++ program to find that given integer is even or odd.

#include<iostream.h>
void main(){
int n;
cout<<"Enter an Integer"<<endl;
cin>>n;
if(n%2==0)
cout<<n<<" is Even Number"<<endl;
else
cout<<n<<" is Odd Number"<<endl;
}

No comments:

Post a Comment