C program to change the case of an alphabet

This C program converts lowercase alphabet to uppercase and uppercase alphabet to lowercase by using if-else statements.

ASCII value of uppercase alphabets ranges from 65-90, and ASCII value of lowercase alphabets ranges from 97-122.

Program:

#include<stdio.h>       
                
void main()       
                
{       
                
 char ch;       
                
 int n;       
                
 printf("Enter an alphabet:");       
                
 scanf("%c",&ch);               
                
 n=ch;       
                
 if(n>=65&&n<=90)        /*if the entered alphabet is in uppercase*/       
                
 {       
                
 n+=32;       
                
 printf("\n %c \n",n);       
                
 }       
                
 else       
                
 if(n>=97&&n<=122)        /*if the entered alphabet is in lowercase*/       
                
 {       
                
 n-=32;       
                
 printf("\n %c \n",n);       
                
 }       
                
 else       
                
 printf("\n Wrong choice!!! \n");       
 } 

OUTPUT:

Enter an alphabet:
F
Enter an alphabet:P
p
Enter an alphabet:4
Wrong choice!!!

Happy coding!!!

About ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ

Linux and Python enthusiast, in love with open source since 2014, Writer at programming-articles.com, India.

View all posts by ᴾᴿᴼᵍʳᵃᵐᵐᵉʳ →

Leave a Reply

Your email address will not be published. Required fields are marked *