1. Character judgment
Enter a character to determine if it is lowercase letter output its corresponding uppercase letter, if it is uppercase letters output its corresponding lowercase, if the digital output number itself, if it is a space, output "space" If this is not the case, the output "other" .
#include <stdio.h>intMain () {Charb; printf ("Please enter a character \ n"); scanf ("%c",&A); if('A'<=a<='Z') {B=a+ +; printf ("%c\n", B); } Else if('a'<=a<='b') {B=a- +; printf ("%c\n", B); } Else if(a=' ') {printf ("space\n"); } Else{printf ("other\n"); } return 0;}
Summary: I am now not very understanding of the conversion is good, just the right to try out. I don't know when to add this thing ', plus it's not very clear.
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 \ n"); scanf ("%d,%d,%d",&a,&b,&c); printf ("Please enter the current date \ n"); scanf ("%d,%d,%d",&d,&e,&f); if(b<e) {printf ("years old is%d\n", g=d-a); } Else if(b=e) {if(c<f) {printf ("years old is%d\n", g=d-a); } Else{printf ("years old is%d\n", g=d-a-1); } } Else{printf ("years old is%d\n", g=d-a-1); } return 0;}
Summary: This age must pay attention to, not only to judge the month, but also to have a date judgment.
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; printf ("Please enter three integers \ n"); scanf ("%d,%d,%d",&a,&b,&c); if(a+b>c) && (a+c>b) && (b+c>a)) {if(a==b&&b==c) {printf ("equilateral triangle \ n"); } Else if((a==b&&b!=c) | | (a!=b&&b==c) | | (a==c&&a!=b)) {if((a*a+b*b==c*c) | | (a*a+c*c==b*b) | | (a*a==c*c+b*b) {printf ("isosceles right triangle \ n"); } Elseprintf ("isosceles triangle \ n"); } Else if((a*a+b*b==c*c) | | (a*a+c*c==b*b) | | (a*a==c*c+b*b) {printf ("right triangle \ n"); } Elseprintf ("General triangle \ n"); } Elseprintf ("non-triangular \ n"); return 0;}
Summary: I feel this problem is the most troublesome, need to consider a lot of situations, at first I want to just filter out to meet the conditions, but I found that I did not reach that level, so only the inappropriate list, and then discharged.
4. See commodity guessing price games
#include <stdio.h>#include<stdlib.h>#include<time.h>intMain () {intb; printf ("Enter the price you guessed, the range is 0----100\n"); scanf ("%d",&a); Srand (Time (NULL)); b=rand ()% -+1; if(a<0|| A> -) {printf ("Error"); } Else if(a==b) {printf ("it's your thing."); } Else if(a<b) {printf ("too low, the correct price is%d\n", B); } Else{printf ("too much, the correct price is%d\n", B); } return 0;}
Summary: Curly braces can not be lost, then there is the setting of random numbers, must be defined first. It takes time to be random.
Ii. Summary of knowledge points in this course
1. Transformation of uppercase and lowercase letters;
2. Random functions;
3. Use time as seed;
Iii. Summary of the experiment
1, must be careful not to use Chinese symbols;
2,== represents equals, = represents assignment;
3, one by one of "{" "}" corresponds
;
4,# include <stdlib.h> and # include <time.h> do not forget;
Third assignment,