C08_Ex 2: Enter one letter. If it is uppercase character, changed to lowercase letters, changed back to uppercase.
// Input a character
// If It's a upper-case character -> change into lower-case character
// If It's a lower-case character -> change into upper-case character
// Use Visual Studio 2005
#include <stdio.h>
void main()
{
char ch;
printf("Input a character: ");
scanf("%c", &ch);
if (ch >= 'a' && ch <= 'z')
ch = ch - 32;
else
if (ch >= 'A' && ch <= 'Z')
ch = ch + 32;
printf("=> Character after changing: %c\n", ch);
}
// If It's a upper-case character -> change into lower-case character
// If It's a lower-case character -> change into upper-case character
// Use Visual Studio 2005
#include <stdio.h>
void main()
{
char ch;
printf("Input a character: ");
scanf("%c", &ch);
if (ch >= 'a' && ch <= 'z')
ch = ch - 32;
else
if (ch >= 'A' && ch <= 'Z')
ch = ch + 32;
printf("=> Character after changing: %c\n", ch);
}
0 Comments:
Post a Comment