1. Character JudgmentEnter 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 not the case, output "other".

#include <stdio.h>voidMain () {CharCh1, CH2; printf ("Please enter a character \ n"); CH1=GetChar (); if(ch1>='A'&&ch1<='Z') {CH2=ch1+ +; printf ("%c\n", CH2); } Else if(ch1>='a'&&ch1<='Z') {CH2=ch1- +; printf ("%c\n", CH2); } Else if(ch1>='0'&&ch1<='9') {ch1=ch1; printf ("%c\n", CH1); } Else if(ch1==' ') {printf ("space\n"); } Else{printf ("other\n"); }}

Summary: 1. Understanding how uppercase lowercase letters are converted because uppercase lowercase ASCII values differ by 32

2. Note that the constant is the "representative"

2. Age issue 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>voidMain () {intA,b,c; intd,e,f; intG; printf ("Please enter the student's 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&&c>=f) | | b<e) {g=d-A; printf ("%d\n", G); } Else if(b==e&&c<f) {g=d-a+1; printf ("%d\n", G); }Else if(b>e) {g=d-a-1; printf ("%d\n", G); }}

Summary: 1. Pay close attention to%d corresponding address

2. Note that the output is the age of the same year without the birthday of the time to subtract one year old

3. Judging the triangle type 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>voidMain () {intA,b,c; printf ("Please enter three integers \ n"); scanf ("%d%d%d",&a,&b,&c); if(a+b<c| | A-b>c) {printf ("non-triangular \ n"); } Else if(a==b&&b==c&&a==c) {printf ("equilateral triangle \ n"); } Else if((a==b&&a*a+b*b==c*c) | | (a==c&&a*a+c*c==b*b) | | c==b&&c*c+b*b==a*a) {printf ("isosceles right triangle \ n"); } Else if((a==b&&a*a+b*b!=c*c) | | (a==c&&a*a+c*c!=b*b) | | c==b&&c*c+b*b!=a*a) {printf ("isosceles triangle \ n"); } Else if((a*a+b*b==c*c) | | (a*a+c*c==b*b) | | c*c+b*b==a*a){printf ("right triangle \ n"); } Else{printf ("General triangle \ n"); }}

Summary: 1. Be aware of the criteria for judging triangles in C language

2. Equals not = (Assignment) = = = (equals)

4. See commodity guessing price games

#include <stdio.h>#include<stdlib.h>#include<time.h>intMain () {intb; Srand (Time (NULL)); b=rand ()% -+1; printf ("Please enter a number \ n"); scanf ("%d",&a); if(a>b) {printf ("the number you typed is too big."); } Else if(a<b) {printf ("the number you typed is too small."); } Else{printf ("you guessed right."); } printf ("This number is%d\n .", B); return 0;}

Summary: 1. When programming, keep a clear eye on who is the number of random numbers who are the output

2. Note that the number between "1,100" is B=rand ()%100+1; don't forget +1.

Additional questions: Bug eating apple problem (complete this question plus 1 points) you bought a box of n apples, unfortunately, when you bought the box into a bug. Insects can eat an apple every x hours, assuming that the worm does not eat another one before eating an apple, how many complete apples do you have after y hours? Enter N,x and y (all integers) to output the remaining number of apples. Test data: 10 4 9 5 3 16

#include <stdio.h>intMain () {intn,x,y,z; printf ("Please enter your number of apples \ n"); scanf ("%d%d%d",&n,&x,&y); if(x<=0|| y<=0|| n<=0) {printf ("error\n"); } Else if(n<=y/x) {printf ("you don't have an apple."); } Else if((float) y/x>y/x) {z=n-y/x-1; printf ("the rest of the apples are%d\n.", z); } Else{z=n-y/x; printf ("the rest of the apples are%d\n.", z); } return 0;}

Summary: Be aware that y/x is not necessarily an integer, pay attention to casting

2016-10-22