if else Statement in C Program
Definition Of if Statement : C Uses the keywords if to implement the decision control instruction. The if statement like to be syntax .
if ( this condition true )
execute statement here;
The Key of if tells the compiler time, when condition is true execute the given statement. Otherwise, Don't Perform The Operation Bellow Statement.If statement conditions like to be bellow.
- x==y x is equal to y
- x!=y x is not equal to y
- x<y x is less than to y
- x>y x is greater than to y
- x<=y x is less than or equal to y
- x>=y x is greater than or equal to y
#include<stdio.h>
int main()
{
int x;
printf("Enter The Number must be 10");
scanf("%d",&x);
if( x==10 )
printf(" x value is %d equal to 10",x);
}
Multiple Statement in if Statement
The Multiple Statement , it may be happen that in a program .we want to be more than one statement extra to be executed . if the expression following if is satisfied. if such multiple statements are to be executed then they must be placed with in a pair of braces .
Following The Example For Multiple Statement
#include<stdio.h>
int main()
{
int bouns,cy,yoj,yr_of_ser;
printf("Enter the Current Year and Year Of Joining ");
scanf("%d%d",&cy,&yoj);
yr_or_ser=cy-yoj;
if( yr_or_ser>3 )
{
bouns=2500;
printf("Bouns=rs %d",bouns);
}
}
if - else Statement
The if Statement , itself will execute a single statement or multiple statement . When the expression following if evaluates to true. the statement will be executed. The expression is false , the else statement will be executed. For Following Syntax and Example Bellow.
Program For if - else
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter The a and b values :");
scanf("%d%d",&a,&b);
c=a+b;
if(c==10)
{
printf("C value equal to 10");
}
else
{
printf("C Value not equal to 10");
}
}
No comments:
Post a Comment