Header Ads Widget

C Program to Reads a Character from Keyboard and Then Print it in Reverse Case Without Using Built-In Functions

Write a C program to accept an alphabet from user and display reverse case of entered alphabet. So, let’s start to develop our program.

Output will be look like this:

Enter any alphabet: N

Lower case of ‘N’ = ‘n’.

Program :

/* Author: CodeTryCatch
*C program to reads a character from keyboard and then print it in 
*reverse case without using built-in functions
void main()
    char alpha;
    printf("Enter any alphabet:");
     printf("\nOutput :\n\n");
    if(alpha>='A'&& alpha<='Z')
       printf("Lower case of '%c' = '%c'",alpha,alpha+32);
    else if(alpha>='a'&& alpha<='z')
       printf("Upper case of '%c' = '%c'",alpha,alpha-32);
        printf("Entered value is not an alphabet");

Step by step descriptive logic of a program.

Step 1 : First we have to declare one variable of char type to accept character value as an input from user.

Step 2 : To print reverse case, first we have to identify case of entered alphabet. For that here we are using if…else conditional structure. If entered alphabet is between ‘A-Z’ then it has capital casing style and vice versa. If both conditions going to fail, then it’s not an alphabet.

Step 3 : To convert alphabet into reverse case, we add 32 into that alphabet. E.g. If I entered ‘A’ then ASCII value of ‘A’ is 65 and to convert it into ‘a’ we need to add 32 into 65 to get 97 which is ASCII value of ‘a’. 

Step 4 : Therefore, in every alphabet’s upper and lower case ASCII value has difference of 32. If we want to convert into lower case, then add 32 on the other hand if wants to convert into upper case then subtract 32 from an alphabet.

Output :

Keep coding...

Thanks for visiting….😊

Post a Comment