Third time job

Source: Internet
Author: User
Tags uppercase letter

Experiment One: Character judgment

1. Experimental Requirements: 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 not the case, output "other".

2. Code:

# include <stdio.h>intMain () {Charc1,c2; printf ("Please enter a character \ n"); scanf ("%c",&C1); if(c1>='A'&&c1<='Z') {C2=c1+ +; printf ("%c", C2); }   Else if(c1>='a'&&c1<=' Z') {C2=c1- +; printf ("%c", C2); }   Else if(c1==' ') {printf ("Space"); }   Else if(c1>=0&&c1<=9) {printf ("%c", C1); }   Else{printf (" Other"); }   return 0;}

3. Operation Result:

4. Summary of Knowledge points: Use "char" when entering characters

Calculation of characters

Use of the IF statement

5. Experiment Summary: Pay attention to "%c"

Equal with "= ="

Experiment Two: Age issues

1. Experimental requirements: Enter a student's birthday (year: Month: Day), and enter the current date (year: Month: Day), calculate the actual age of the students (years).

2. Code:

#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 the current date:"); scanf (" %d%d%d",&d,&e,&f); if(e>b| | e==b&&f>=c) {g=d-A; printf ("you're%d years old.", G); }    Else if(e<b) {g=d-a-1; printf ("you're%d years old.", G); }    return 0; }

3. Operation Result:

4. Summary of Knowledge Points: use of the IF statement

Or and and the application

5. Experimental summary: If the parentheses can be used together or and and

Experiment three: Judging the type of triangle

1. Experimental requirements: Enter three integers to determine the type of triangle (equilateral triangle, isosceles triangle, isosceles right triangle, right triangle, general triangles, and non-triangles)

2. Code:

#include <stdio.h>intMain () {intA,b,c; printf ("Please enter the three-side length of the triangle \ n"); scanf (" %d%d%d",&a,&b,&c); if(a<0|| b<0|| c<0) {printf ("Input Data Error"); }    Else if(a+b<c| | a+c<b| | b+c<a) {printf ("Non-triangular"); }    Else if(a==b&&b==c) {printf ("equilateral triangle"); }    Else if(a==b| | a==c| | b==c) {printf ("isosceles Triangle"); }    Else if(a*a+b*b==c*c | | a*a+c*c==b*b | | b*b+c*c==a*a) {printf ("Right Triangle"); }    Else if(a*a+b*b==c*c | | a*a+c*c==b*b | | b*b+c*c==a*a) {if(a==b| | a==c| | b==c) {printf ("isosceles Right Triangle"); }    }    Else{printf ("General Triangles"); }    return 0;}

3. Operation Result:

Experiment Four:

Look at the commodity guess the price small game

Code:

#include <stdlib.h>#include<stdio.h>#include<time.h>intMain () {intb; printf ("Please guess the price (an integer within 100) \ n");    Srand (Time (NULL)); A=rand ()% -+1; scanf ("%d",&b); if(b<=0|| B> -) {printf ("input error \ n"); }    Else if(b==a) {printf ("Congratulations, you guessed it! \ n"); }    Else if(b>a) {printf ("guess it's high."); }      Else if(b<a) {printf ("guess it's low."); }    return 0; }

Operation Result:

Knowledge Point Summary: If statement application

Or and and the application

Use "char" when entering characters

Calculation of characters

Experiment Summary: Pay attention to "%c"

Equal with "= ="

If the parentheses can be used or both and

Third time job

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.