C program to read a character from keyboard and print it in reverse case i.e if input is lower case output will be upper case and vice versa

This is a C program to print character in reverse case i.e. the program will read a character from keyboard and then print that character in lower case if it is in upper case or print in upper case if that input character is in lower case.  This program will use c programming library functions like islower(), isupper(), toupper() and tolower(). All these functions are defined under header file <ctype.h>.

C program to print character in reverse case

#include <stdio.h>
#include <ctype.h>
main()
{
  char x;
  printf("Enter an alphabet :");
  x = getchar(); // read a character from keyboard
  if (islower(x))
     putchar(toupper(x)); //change to uppercase
  else
     putchar(tolower(x)); //else change to lowercase
}

[adsense1]

 

OUTPUT

Enter an alphabet : d
D
Enter an alphabet : y
Y

Explanation of the program

In this program c programming functions like islower(), isupper(), toupper() and tolower() are used which are defined under header file called . That’s why it is included after standard header file under which input output functions like printf and other are defined.