Signup/Sign In
LAST UPDATED ON: SEPTEMBER 17, 2024

C Program to reverse the case of input character

Below is a program to reverse the case of input character.

getchar() is similar to scanf().

islower() is system defined function under ctype.h header file to check if the character is in lowercase or not.

toupper() converts the input parameter into equivalent uppercase char.

putchar() is similar to printf().

#include<stdio.h>
#include<ctype.h> // to use system defined function islower & toupper

int main()
{
    printf("\n\n\t\tStudytonight - Best place to learn\n\n\n");

    char alphabet;
    printf("Enter an alphabet : ");
    putchar('\n');  // to move to next Line

    alphabet=getchar();

    printf("\n\nReverse case of %c is :  ",alphabet);

    if(islower(alphabet))
        putchar(toupper(alphabet));

    else 
        // must be an uppercase character
        printf("%c",tolower(alphabet)) ;

    printf("\n\n\t\t\tCoding is Fun !\n\n\n");
    return 0;
}

Output:

Reversing case of character