C Program to toggle letter case

Simple C program to toggle alphabet case. For example if a character is 'S' then after toggle it will be 's'.
#include<stdio.h>
int main()
{
 char ch;
 printf("Enter an alphabet: ");
 scanf("%c",&ch);
 printf("Alphabet befor toggle: %c\n",ch);
 if(ch>='a'&&ch<='z')
 {
 ch=ch-32; //or use ch=ch-'a'+'A';
 }
 else
 if(ch>='A'&&ch<='Z')
 {
  ch=ch+32; //or use ch=ch-'A'+'a'
 }
 printf("Alphabet after toggle: %c",ch);
 return 0;
}



Popular posts from this blog