# include<iostream>
using namespace std;
void main()
{
cout<<"Enter any number";
cin>>a;
if(a==0)
cout<<"value of a is o"<<endl;
else if(a==2)
cout<<"Value of a is 2"<<endl;
else if(a==3)
cout<<"Value of a is 3"<<endl;
else
cout<<"Value of a is not 0,2 and 3"<<endl;
}
using namespace std;
void main()
{
cout<<"Enter any number";
cin>>a;
if(a==0)
cout<<"value of a is o"<<endl;
else if(a==2)
cout<<"Value of a is 2"<<endl;
else if(a==3)
cout<<"Value of a is 3"<<endl;
else
cout<<"Value of a is not 0,2 and 3"<<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.....!
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 value of a is 2,then the command transfers to thie statement and this statement is printed:-
"Value of a is 2"...!
and if the user gives value of a is 3,then the command transfers to thie statement and this statement is printed:-
"Value of a is 3"...!
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,(Explain in this link:-http://jdrana.blogspot.com/2013/11/if-else-statement.html)
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,(Explain in this link:-http://jdrana.blogspot.com/2013/11/if-else-statement.html)
I hope you wil got this..!
Feel free to give suggestions in comment box.......!
Feel free to give suggestions in comment box.......!
0 comments:
Post a Comment