C Program to convert alphabets from lowercase to uppercase

      This program converts given alphabet from lowercase to uppercase.
Every character in c programming are stored as ASCII values. The value of ‘A’ and ‘a’ in ASCII are 65 and 97 respectively.
Since there is diffrence of 32 between these two numbers one need to subtract 32 from lowercase letter to convert it into uppercase.
This is achieved logically using ‘A’-‘a’ or simply by subtracting 32 from given character.

convert lowercase to uppercase program in c



Source Code:

#include<stdio.h>
 int main(void)
 {
  int ch,n;
  ch=getchar();
  n=(ch>='a')&&(ch<='z')? 
        putchar(ch+'A'-'a'): putchar(ch);
  return 0;
  }


edit-code-image

Sample Test cases:

1.a
  A

2.s
  S

3.d
  D

Explanation:

Step 1: A character is read from the user using getchar() function.

Step 2: If character is already in lowercase it is printed as it is otherwise it is converted
to uppercase by substacting 32 and then printed to output screen.

More Insights:

1. More about ASCII

More Content:Explore More