In C every character has a ASCII number. Here we can use this concept for this program.
First we take a input from user. Then we check whether it is an alphabet or not and also check whether it is in capital or in small letter. If it is in capital then we add 32 with the character's ASCII value.
If it is in small letter then we subtract 32 from the character's ASCII value.
For your convenience here is the ASCII chart.
Now the the example ....
#include<stdio.h>
#include<ctype.h>
int main()
{
char c;
printf("Enter a alphabet ");
scanf("%c",&c);
if(isalpha(c))
{
if(c<'a')
{
c+=32;
printf("\nYou have entered capital letter\nThe corresponding small letter is %c\n",c);
}
else
{
c-=32;
printf("\nYou have entered small letter\nThe corresponding capital letter is %c\n",c);
}
}
return 0;
}
The output of this program will be....
First we take a input from user. Then we check whether it is an alphabet or not and also check whether it is in capital or in small letter. If it is in capital then we add 32 with the character's ASCII value.
If it is in small letter then we subtract 32 from the character's ASCII value.
For your convenience here is the ASCII chart.
Now the the example ....
#include<stdio.h>
#include<ctype.h>
int main()
{
char c;
printf("Enter a alphabet ");
scanf("%c",&c);
if(isalpha(c))
{
if(c<'a')
{
c+=32;
printf("\nYou have entered capital letter\nThe corresponding small letter is %c\n",c);
}
else
{
c-=32;
printf("\nYou have entered small letter\nThe corresponding capital letter is %c\n",c);
}
}
return 0;
}
The output of this program will be....
Bravo!!!!This is really amazing and unbelievable.You have done a miracle.Thanks.
ReplyDeleteThank you Saikat
ReplyDelete