Categories: C

Miscellaneous Program(reverse the case of input string)

A program to reverse the case of input characters is provided below.

islower() is a system-defined function in the ctype.h header file that determines whether a character is in lowercase.

toupper() converts an input parameter to an uppercase equivalent.

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

int main()
{
    
    char word[10];
    printf("Enter a word : ");
 
    gets(word);
    putchar('\n');  // to move to next Line
   for(int i=0;i<10;i++){
    

    char alphabet=word[i];

    if(islower(alphabet))
       word[i]=toupper(alphabet);

    else 
       
        word[i]=tolower(alphabet);
}
printf("%s",word);
   
    return 0;
}

Output:

Enter a word : CoderzPy
cODERZpY

Here, we can clearly see that the cases of all the characters in the input string are reversed.

Note: also read about the Miscellaneous Program(Palindrome Number)

Follow Me

If you like my post please follow me to read my latest post on programming and technology.

https://www.instagram.com/coderz.py/

https://www.facebook.com/coderz.py

Share
Published by
Rabecca Fatima

Recent Posts

Estimate π Using Monte Carlo Method

The formula for the area of a circle is given by πr². Use the Monte…

5 days ago

Longest Substring with K Distinct Characters

Given an integer k and a string s, write a function to determine the length…

6 days ago

Staircase Climbing Ways

There is a staircase with N steps, and you can ascend either 1 step or…

2 weeks ago

Autocomplete System Implementation

Build an autocomplete system that, given a query string s and a set of possible…

2 weeks ago

Job Scheduler Implementation

Design a job scheduler that accepts a function f and an integer n. The scheduler…

2 weeks ago

Largest Sum of Non-Adjacent Numbers

Problem Statement (Asked By Airbnb) Given a list of integers, write a function to compute…

2 weeks ago