Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- /* ascii letters is a range of
- numbers within a total amount
- of numbers.
- lowercase 97-122 a-z
- uppercase 65-90 A-Z
- to make a lowercase to
- an uppercase -32 to
- the value of the lowercase
- to make uppercase to
- lowercase +32 to
- the value of the uppercase */
- char a,b;
- printf("enter a letter,\n"
- "Upper or Lower case\n");
- scanf(" %c",&a);
- /* this is assuming an
- actual letter is being
- inputted. */
- if(a >= 65 && a <= 90)
- printf("\nchanged to \n"
- "lowercase %c \n", a+=32);
- else
- printf("wrong input %c\n",a);
- if(a >= 97 && a <= 122)
- printf("\nchanged to\n"
- "uppercase %c\n",a-=32);
- else
- printf("wrong input %c\n",a);
- printf("using a switch to "
- "switch it back\n");
- switch(a){
- case 65 ... 90:
- printf("\nchanged to \n"
- "lowercase %c \n", a^=32);
- break;
- case 97 ... 122:
- printf("\nchanged to\n"
- "uppercase %c\n",a^=32);
- break;
- default:
- printf("\nwrong input %c\n",a);
- }
- /*
- getting the value between the letters
- regardless of what they are.
- using the above:
- Lower case letter (minus) upper case letter.
- So it's get the integer values of each
- letter. The lower case is the higher
- numbers in the ASCII Table so subtract
- the upper case value with the lower case
- value to get the difference.
- Input lower case letter
- g = 103
- input upper case letter
- B = 66
- Different is g minus B or
- X=103-66
- char is an integer so you can easily get
- the number of the letter by simply changing
- the data type.
- char d='h';
- int f = (int)d;
- printf("%d %c",f,f);
- 104 h
- */
- printf("the difference between 2 "
- "letters\nenter an lower case letter\n");
- scanf(" %c",&a);
- printf("\nenter an upper letter\n");
- scanf(" %c",&b);
- /* lowercase 97-122 a-z
- uppercase 65-90 A-Z */
- if (a >= 97 && a <= 122 &&
- b >= 65 && b <= 90)
- /* put everything in one printf */
- printf("the ascii integer value "
- "difference between the two"
- " are\n%c - %c\n%d - %d\n"
- "= %d\n",a,b,a,b,(int)a-(int)b);
- else
- printf("you failed to follow instructions\n"
- "%c :: %c\n",a,b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement