Different forms of implementation of if-statement are :
- Simple if statement
- if-else statement
- Nested if-else statement
- Else if statement
Simple if statement
This is used to executed the statements only if the condition is true.
Syntax :
if(condition) { block of statement; }
Example :
#include <stdio.h>
int main()
{
int number = 0;
printf("\nEnter an integer : ");
scanf("%d",&number);
if (number > 10)
{
printf("\nYou entered %d which is greater than 10\n", number);
}
if (number < 10)
{
printf("\nYou entered %d which is less than 10\n", number);
}
return 0;
}
Output :
Enter an integer : 8 You entered 8 which is less than 10
No comments:
Post a Comment