1.
#include <stdio.h>intMain () {CharA; printf ("Please enter a character"); scanf ("%c",&a); if(a>='A'&&a<='Z') {a=a+ +; printf ("%c", a); } Else if(a>='a'&&a<='Z') {a=a- +; printf ("%c", a); } Else if(a>='0'&&a<='9') {printf ("%c", a); } Else if(a==' ') {printf ("Space"); } Else{printf (" Other"); } return 0;}
2.
#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(b>e) {g=d-a-1; } Else if(b=e) {if(c>f) {g=d-a-1; } Else{g=d-A; } } Else{g=d-A; } printf ("real age is%d", G); return 0;}
3.
#include <stdio.h>intMain () {intA,b,c; printf ("Please enter three sides of the triangle"); scanf ("%d,%d,%d",&a,&b,&c); if(a+b>c&&a+c>b&&b+c>a&&a-c<b&&a-b<c&&b-c<a) {if((a==b&&a!=c) | | (a==c&&a!=b) | | b==c&&b!=a) {printf ("isosceles Triangle"); } Else if(a==b&&b==c) {printf ("equilateral triangle"); } Else if((a*a+b*b==c*c) | | (b*b+c*c==a*a) | | a*a+c*c==b*b) {printf ("Right Triangle"); } Else if((a==b&&a*a+b*b==c*c) | | (a==c&&a*a+c*c==b*b) | | b==c&&b*b+c*c==a*a) {printf ("isosceles Right Triangle"); } Else{printf ("General Triangles"); } } Else{printf ("Non-triangular"); } return 0;}
4.
#include <stdio.h>#include<stdlib.h>#include<time.h>intMain () {intb; printf ("Please enter the price"); scanf ("%d",&a); Srand (Time (NULL)); b=rand ()% -+1; if(a> -|| a<0) {printf ("Please re-enter"); } Else if(a<b) {printf ("guess it's low, it should be%d.", B); } Else if(a==b) {printf ("Congratulatins"); } Else{printf ("guess it's high, it should be%d.", B); } return 0;}
Experiment Summary: Before writing the code, must adjust the good order
At the time of writing, remember what that variable means.
Learned a new function
&& | | Or did not make a quick distinction.
Summary of Knowledge points: Do not add semicolons after the IF statement;
To understand the usage of%d and%c
Third time job