/*Control Statement: Simple if statement*/
By Default the instructions in a program are executed sequentially.
and many a times, we want a set of instructions to be executed in one situation, and an entirely different set of instruction to be executed in another situation. In that time, Control statements allow us to change the sequence of instructions for execution. In other word, control statement define how the control is transferred to other parts of the program. In C language there are four types of control statements which are as-
In the if statement the if keyword is used. if keyword is always enclosed within a pair of parentheses. If the condition, whatever is it, is true, then the statement is executed otherwise skipped it.
The syntax of the simple if statement:
if(this condition is true)
execute this statement;
The Flowchart of if statement:
The Example of if statement:
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
printf("enter a number less than 5 =");
scanf("%d",&num);
if(num<5)
printf("This is called simple if statement");
getch();
}
Output:
In general we express the condition using relational operators. the relational operators allow us to compare two values to see whether they are equal to each other, unequal, or whether one is greater than other or less than. So this table define how can use relational operators in different conditions.
By Default the instructions in a program are executed sequentially.
and many a times, we want a set of instructions to be executed in one situation, and an entirely different set of instruction to be executed in another situation. In that time, Control statements allow us to change the sequence of instructions for execution. In other word, control statement define how the control is transferred to other parts of the program. In C language there are four types of control statements which are as-
- if statement
- goto statement
- switch statement
- loop
The if statement in C can be used in various forms.
i.) simple if statement
ii.) if else statement
iii.) Nested if-else Statement
iv.) else-if Ladder
- The simple if Statement:
- The simple if Statement:
In the if statement the if keyword is used. if keyword is always enclosed within a pair of parentheses. If the condition, whatever is it, is true, then the statement is executed otherwise skipped it.
The syntax of the simple if statement:
if(this condition is true)
execute this statement;
The Flowchart of if statement:
The Example of if statement:
#include<stdio.h>
#include<conio.h>
void main()
{
int num;
printf("enter a number less than 5 =");
scanf("%d",&num);
if(num<5)
printf("This is called simple if statement");
getch();
}
Output:
In general we express the condition using relational operators. the relational operators allow us to compare two values to see whether they are equal to each other, unequal, or whether one is greater than other or less than. So this table define how can use relational operators in different conditions.
This expression | is true if |
x==y | x is equal to y |
x!=y | x is not equal to y |
x<y | x is less than y |
x<y | x is greater than y |
x<=y | x is less than or equal to y |
x>=y | x is greater than or equal |
No comments:
Post a Comment