Ticker

6/recent/ticker-posts

C Language (Else if statement)

ELSE IF STATEMENT IN C
The else if statement is used to implement two and more than two logical conditions that cannot be implement by If else and conditional operator, so if you want to implement more than two condition then else if statement is solution for it.

Example 1: Program to find grade in C
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int m;
printf("Enter your marks:");

scanf("%d",&m);

if(m>=33 && m<50)
printf("Grade C");

else if(m>=50 && m<75)

printf("Grade B");


else if(m>=75 && m<=100)

printf("Grade A");

getch();
}









Example 2: Program to enter element is number, small alphabet, capital alphabet or special symbol
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char c;
printf("Enter any element:");

scanf("%c",&c);

if(c>=65 && c<=90)
printf("Capital alphabet");

else if(c>=97 && c<=122)

printf("Small alphabet");



else if(c>=48 && c<=57)

printf("Number");

else
printf("Special character");
getch();
}


















Post a Comment

0 Comments