Program 12) A program that reads a character from keyboard and then prints it in reverse case. That is, if the input is upper case,the output will be lower case.
The program uses three functions: islower, toupper, tolower. The function islower is a conditional function and takes the value TRUE if the argument is a lowercase alphabet; otherwise takes the value FALSE. The function toupper converts the lowercase arguement into an uppercase alphabet while the function tolower does the reverse.
PROGRAM
#include <stdio.h>
#include <ctype.h>
main( )
{
char alphabet ;
printf("Enter an alphabet") ;
putchar('\n') ; /* move to next line */
alphabet = getchar( ) ;
if(islower(alphabet) )
putchar(toupper(alphabet) ) ;
else
putchar(tolower(alphabet) ) ;
getch( ) ;
}
Output: Enter an alphabet
a
A
Enter an alphabet
Q
q
Enter an alphabet
z
Z
No comments:
Post a Comment