Basic

Switch Case

Goto

Operators

if Statement

Nested if

While Loop

For Loop

Array

Patterns

Excersises


C Program to Convert Upper Case Character to Lower Case


In this program, we are getting a Upper Case character as input from the user and Convert it to Lower Case.

How to Convert?

We are going to convert upper case to lower case using ASCII value of character.

  • The difference between ASCII value of Uppercase alphabet and it Lowercase equivalent alphabet is 32. For ex,   ASCII value of 'B' is 66   ASCII value of 'b' is 98   ASCII of 'b' - ASCII of 'B' = 98 - 66 = 32
  • If we want convert Lowercase alphabet to Uppercase, we have to subtract 32 of ASCII value.   ASCII of 'b' - 32 = 98 - 32 = 66 (B)
  • Likewise If we want convert Uppercase alphabet to Lowercase, we have to add 32 of ASCII value.   ASCII of 'B' + 32 = 66 + 32 = 98 (b)

Example : pgm.c



#include<stdio.h>
void main()
{
  char ch;

  printf("Enter the Upper Case Character: ");
  scanf("%c",&ch);

  //check given character is upper
  if(ch>=65 && ch<=90)
  {
    //convert to lower
    ch=ch+32;
  }

  printf("Lower Case Character is %c",ch);

}

Output:

Enter the Upper Case Character: B
Lower Case Character is b