To convert Alphabet to Upper or Lower case we need to change the ASCII code of the Alphabet.
ASCII code can be define as the code of a character i.e. integer value of the character.
The codes from 65 to 90 are Uppercase Alphabet, which are A to Z. where A is 65 & so on.
And the codes from 97 to 122 are Lowercase Alphabet, which are a to z. where a is 92 & so on.
Here A is 65 and a is 97, the difference between two is 32. So if I want to convert A to a. I’ll add +32 to the ASCII code, which is converting 65 to 92. Opposite we’ll do to convert a to A which is -32. And this is same for all alphabets, so now you got the logic.
Now lets proceed to the Program
To convert Uppercase Alphabet to Lowercase Alphabet [e.g a to A]
Input: A
Output: a
logic: alphabet+32
To convert Lowercase Alphabet to Uppercase Alphabet [e.g A to a]
Input: a
Output: A
logic: alphabet-32
ASCII code can be define as the code of a character i.e. integer value of the character.
The codes from 65 to 90 are Uppercase Alphabet, which are A to Z. where A is 65 & so on.
And the codes from 97 to 122 are Lowercase Alphabet, which are a to z. where a is 92 & so on.
Here A is 65 and a is 97, the difference between two is 32. So if I want to convert A to a. I’ll add +32 to the ASCII code, which is converting 65 to 92. Opposite we’ll do to convert a to A which is -32. And this is same for all alphabets, so now you got the logic.
Now lets proceed to the Program
To convert Uppercase Alphabet to Lowercase Alphabet [e.g a to A]
Input: A
Output: a
logic: alphabet+32
//to convert uppercase alphabet to lowercase
#include<stdio.h>
#include<conio.h>
void main()
{
char n,i;
clrscr();
printf("Enter a lower case alphabet\n\n");
scanf("%c",&n);
i=n+32;
printf("%c",i);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
char n,i;
clrscr();
printf("Enter a lower case alphabet\n\n");
scanf("%c",&n);
i=n+32;
printf("%c",i);
getch();
}
To convert Lowercase Alphabet to Uppercase Alphabet [e.g A to a]
Input: a
Output: A
logic: alphabet-32
//to convert lowercase alphabet to uppercase
#include<stdio.h>
#include<conio.h>
void main()
{
char n,i;
clrscr();
printf("Enter a lower case alphabet\n\n");
scanf("%c",&n);
i=n-32;
printf("%c",i);
getch();
}
Hope you liked my posts, give comments if you have any doubts.. :)#include<stdio.h>
#include<conio.h>
void main()
{
char n,i;
clrscr();
printf("Enter a lower case alphabet\n\n");
scanf("%c",&n);
i=n-32;
printf("%c",i);
getch();
}
Categories:
c program
0 comments:
Post a Comment