If, If-else, Else if, and Switch Statement Program in C

if Statement Program

#include <stdio.h>
int main()
{
int ramage = 35;
int mohanage = 30;
if(ramage > mohanage)
{
printf(“Ram is elder.”);
}
return 0;
}

Output

Ram is elder.

if-else Statement Program

#include <stdio.h>
int main()
{
int ramage = 30;
int mohanage = 35;
if(ramage > mohanage)
{
printf(“Ram is elder.”);
}
else
{
printf(“Mohan is elder.”);
}
return 0;
}

Output

Mohan is elder.

else if Statement Program

if(ramage > mohanage)
{
printf(“Ram is elder”);
}
else if(mohanage > ramage)
{
printf(“Mohan is elder”);
}
else
{
printf(“Both are equal”);
}

Output

Both are equal

Switch Statement Program

#include <stdio.h>
void main()
{
int num;
printf(“Enter a number “);
scanf(“%d”,& num);
switch(num)
{
case 1: printf(“First Case executed”);
break;
case 2: printf(“\n Second Case executed”);
break;
default: printf(“\n Plz enter 1 or 2 number”);
break;
}
}

Output

Enter a number : 1
First Case executed