Syntax :
if(condition) { block 1 of statement; } else { block 2 of statement; }
if condition is true then block 1 statement will be executed and if condition is false block 2 statement will execute.
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);
}
else
{
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