C Program to implement Simple if statement
Syntax of Simple-if
—————————-
—————————-
if(condition)
{
statement1;
statement2;
.
.
.
statement n;
}
{
statement1;
statement2;
.
.
.
statement n;
}
Simple C Program to understand Simple if:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
#include<stdio.h> void main() { int age; printf(" >>> c program to implement simple if<<< \n\n"); printf("\n Enter the age of the person: "); scanf("%d",&age); if(age>=18) { printf("\n Eligible for voting \n"); } printf("\n program ends \n\n"); } |
output:
Explanation:
In the above program, the control enters into the if block only if the condition is true. And the statement printf(“\n program ends \n\n”); is executed every time.