If statement.
It is a conditional statement. It conditionally executing a
branch of statements .There are different types of if statement.
1.
simple if
2.
if-else
3.
if-else if-else
4.
switch statement.
Simple If statement:
A relational expression is checked.
If the condition is true a block of coding will be executed.if it returns false the block of coding will not
get executed.
For example take the following c
program
.
#include<stdio.h>
#include<conio.h>
void main()
{
int mark;
int mark;
Clrscr();
printf(“enter your score”);
scanf(“%d”,&mark);
printf(“your score is %d”,mark);
if(mark>=90)
{
printf(“excellent”);
}
getch();
}
Program explanation:
The above program asks the score
as input. It prints your mark.if your
mark>=90 then it additionally prints the output excellent.
If—else
In this case a relational
expression is tested .if the result is true then a block of coding will be executed.if
it returns false another block of coding will be executed.
#include<stdio.h>
#include<conio.h>
void main()
{
int mark;
int mark;
Clrscr();
printf(“enter your score”);
scanf(“%d”,&mark);
printf(“your score is %d”,mark);
if(mark>=40)
{
printf(“pass”);
}
Else
{
Printf(“fail”);
}
getch();
}
Program explanation:
In the above c program mark is input.
If it is greater than or equal to 40
result is printed as false.
If the mark<40 else part will
be executed and printed as fail
--------to be continued
muthu karthikeyan madurai
No comments:
Post a Comment