I explain first program of C using if condition and also explain if condition with example
1. Describe the structure of the simple if statement.
Ans:
The structure of the simple if statement is:
If( condition){
Statements1;
Statements2; [ Body of the if condition]
… … … ….
… … …. ….
Statements n
}
Explanation: if – Gi
conditional part wU
mZ¨ n‡j if – Gi
Body
execute nB‡e Ab¨_vq if – Gi
Body execute nB‡e bv|
2. Describe the structure of the compound if statement.
Ans:
The structure of the simple if statement is:
If( condition){
Statements1;
Statements2; [true part]
… … … ….
… … …. ….
Statements n
}
else
{
Statements1;
Statements2; [false part]
… … … ….
… … …. ….
Statements n
}
Explaination: if – Gi
conditional part wU
mZ¨ n‡j if – Gi
True Body A_©vr if – Gi cÖ_g Ask execute nB‡e Ab¨_vq if – Gi false Body A_©vr
if – Gi wØZxq Ask execute nB‡e|
3. Write a program which will print the sentence “It is
rainy season” after getting ‘1’ from key board and will print “It is summer season”
after getting ‘2’ from key board.
#include<stdio.h>
#include<conio.h>
void main(){
int dada;
printf("\nEnter a value form key
board = ");
scanf("%d",&dada);
if(dada == 1)
{
printf("\nIt
is rainy season");
}
if(dada == 2)
{
printf("\nIt is
summer season");
}
}
No comments:
Post a Comment