Wednesday, 20 November 2013

If else Statement

# include<iostream>
using namespace std;
void main()
{
cout<<"Enter any number";
cin>>a;
if(a==0)
cout<<"value of a is o"<<endl;
else
cout<<"Value of a is not zero"<<endl;

}

In this program,
we will take value from user,the value user gives is store in a(data type int)
If the user give inout o(zero),then the program says that:-
"Value of a is o".......!!
How is this possible,Actually if statement is a check which will check either value of a is zero nor not..!
If it is zero then Program says that,Valus is zero.....!
but if it is not zero then the command transfers to the else,and the program says,
"Value of a is not zero"..!
Note:-
If you want one statement to be executed with if and else,then no need to place braces(show in program),but if two or more statements are,then you will put braces like this:-
if(a==0)
{
cout<<"I am Junaid"<<endl;
cout<<"Value of a is o"<<endl;
}
else
{
cout<<"I am Rana"<<endl;
cout<<"Value of a is not zero"<<endl;
}
I hope you wil got this..!
Feel free to give suggestions in comment box.......!

0 comments: