Pages

Friday, July 31, 2020

IF ELSE STATEMENT IN C


The If else statement is used to implement atmost two logical conditions. 

Example 1: Program to print result by If else
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int m;
printf("Enter your marks:");
scanf("%d",&m);
if(m >= 33)
{
printf("Pass");
}
else
printf("Fail");
getch();
}

- - - OUTPUT - - -
Enter your marks: 35
Pass


Example 2: Even odd program in C
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n;
printf("Enter any number:");
scanf("%d",&n);
if(n%2 == 0)
{
printf("Even");
}
else
printf("Odd");
getch();
}

- - - OUTPUT - - -
Enter any number: 3
Odd


Example 3: Leap year program in C
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int year;
printf("Enter the year");
scanf("%d",&year);
if(year%4 == 0)
{
printf("Leap year");
}
else
printf("Not leap year");
getch();
}

- - - OUTPUT - - -
Enter the year: 2019
Not leap year


                                                                                          ELSE IF STATEMENT>>

No comments:

Post a Comment