C language support if-else-if statement to test additional condition apart from the initial text expression.In this kind of statement numbers of logical statement is checked for executing various statement,if any logical statement is TRUE then compiler executes the block followed by if condition
otherwise it skipes and execute else block.
ads
Syntax-:
if(condition-1)
statement-1;
elseif(condition-2)
statement-2;
elseif(condition-3)
statement-3;
else
statement-4;
}
Example-:
#include<stdio.h>
#include<conio.h>
main()
{char ch;
printf("Enter any character");
scanf("%c",&ch);
if(ch>=65)&&(ch<=90)
printf("%c is an alphabet in uppercase",ch);
elseif(ch>=97)&&(ch<=122)
printf("%c is an alphabet in lower case",ch);
elseif(ch>=48)&&(ch<=57)
printf("%c is a digit",ch);
else
printf("%c is a special symbol",ch);
getch();
}
Output-:Enter any character S
S is an alphabet in uppercase
NOTE-: Numeric values in above program are the ASCII values of characters,to learn more about ASCII values, CLICK HERE
share it
ReplyDelete