Q53 Write a program to convert lowercase character to uppercase and vice versa.

Before writing program for lowercase to uppercase and vice versa conversion, we should know ascii value corresponding lowercase and uppercase alphabets.

A – Z  = 65 – 90

a – z  =  97 – 122

Try below program:

#include<stdio.h>

int main()

{

        char ch , chr;

        scanf(“%c”,&ch);

        chr = ((ch >= ‘A’ && ch <= ‘Z’) ? (ch + ‘a’ – ‘A’) : (ch + ‘A’ – ‘a’));

        printf(“%c”,chr);

}

Output:

$ ./a.exe

Z

z

$ ./a.exe

d

D

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.