Using Conditional Statements
The if statement is used to check the condition. If Condition is true Then particular code execute and if condition is not true then it pass to else statement, and that code is execute within else. & else statement is not necessary every time. Check Out One Program to better Understand
#include<iostream.h>
#include<conio.h>
int main()
{
int a; //a integer variable define
cout << "Enter Any Number\n";
cin >> a; // take value in a
if(a%2 == 0) //check if a%2 == 0 then code execute
{
cout << "Its Even Number\n";
} // code should be written in braces
else
{
cout << "Its Odd Number\n";
}
getch();
return 0;
}
OUTPUT
The if statement is used to check the condition. If Condition is true Then particular code execute and if condition is not true then it pass to else statement, and that code is execute within else. & else statement is not necessary every time. Check Out One Program to better Understand
#include<iostream.h>
#include<conio.h>
int main()
{
int a; //a integer variable define
cout << "Enter Any Number\n";
cin >> a; // take value in a
if(a%2 == 0) //check if a%2 == 0 then code execute
/* a%2 means value of a divide by 2 and if the remainder comes out to be zero then its display its Even Number.
*/{
cout << "Its Even Number\n";
} // code should be written in braces
else
/* Else Dont Require any argument So you need to type else only and rest of code that execute if, if statement is false
Here if a%2 is other than 0 then its show Its Odd Number.
*/{
cout << "Its Odd Number\n";
}
getch();
return 0;
}
OUTPUT
0 comments:
Post a Comment