1. Character judge input a character, judge if it is lowercase letter output its corresponding uppercase letter, if it is uppercase letters output its corresponding lowercase, if it is the digital output number itself, if it is a space, output "space", if not the case, output "other".
#include <stdio.h>intMain () {CharC; printf ("Please enter a character:"); scanf ("%c",&c); if(c>='a'&&c<='Z') {C=c- +; printf ("%c\n", c); } Else if(c>='A'&&c<='Z') {C=c+ +; printf ("%c\n", c); } Else if(c>='0'&&c<='9') {printf ("%c\n",&B); } Else if(c=' ') {printf ("space\n"); } Else{printf ("other\n"); } return 0;}
* Mastering and familiarity with input and output formats using character data
2. Age issues
Enter a student's birthday (year: Month: Day), and enter the current date (year: Month: Day) to calculate the actual age (years) of the birth.
#include <stdio.h>intMain () {inta,b,c,d,e,f,g; printf ("Please enter your birthday."); scanf ("%d%d%d",&a,&b,&c); printf ("Please enter today's date"); scanf ("%d%d%d",&d,&e,&f); if(a==d) {printf ("you're 0 years old ."); } Else if(a<d) {if(b<e) {g=d-A; printf ("you're%d years old .", G); } Else if(b>e) {g=d-a-1; printf ("you're%d years old .", G); } Else { if(c<=f) {g=d-A; printf ("you're%d years old .", G); } Else{g=d-a-1; printf ("you're%d years old .", G); } } } Else{printf ("Input Error"); } return 0;}
The nested format of the *if else statement is used with the attention of the indented format, the curly braces are easy to throw away or cannot match the other half of the corresponding, it is best to first write the first layer and then write the nested content.
3. Judging the type of triangle
Enter three integers to determine the type of triangle (equilateral triangle, isosceles triangle, isosceles right triangle, right triangle, general triangles, and non-triangles)
#include <stdio.h>intMain () {inta,b,c,d,e,f,g; printf ("Please enter your birthday."); scanf ("%d%d%d",&a,&b,&c); printf ("Please enter today's date"); scanf ("%d%d%d",&d,&e,&f); if(a==d) {printf ("you're 0 years old ."); } Else if(a<d) {if(b<e) {g=d-A; printf ("you're%d years old .", G); } Else if(b>e) {g=d-a-1; printf ("you're%d years old .", G); } Else { if(c<=f) {g=d-A; printf ("you're%d years old .", G); } Else{g=d-a-1; printf ("you're%d years old .", G); } } } Else{printf ("Input Error"); } return 0;}
* Note the difference "" "" "" 4. Look at the commodity guess the price small game
#include <stdlib.h>#include<stdio.h>#include<time.h>intMain () {intb; printf ("Please guess the price of this product in 1-100 rooms"); scanf ("%d",&a); Srand (Time (NULL)); b=rand ()% -+1; if(a==b) {printf ("the merchandise belongs to you."); } Else if(a<b) {printf ("it's too small."); } Else{printf ("it's too big."); } return 0;}
Third time job