Third time job

Source: Internet
Author: User

One, guess Price game

Experimental requirements: Look at the commodity guessing price games

Code:

#include <stdio.h>#include<stdlib.h>#include<time.h>intMain () {intb;    Srand (Time (NULL)); A=rand ()%Ten+1; printf ("Please enter what you think is the price \ n"); scanf ("%d",&b); if(a==b) {printf ("Congratulations, you guessed right. \ n"); }    Else{printf ("you guessed wrong, the correct price is%d\n", a); }    return 0;}

Operation Result:

Experiment Summary: Pay attention to the time setting

Second, the Age problem

Experimental requirements:

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.

Code:

#include <stdio.h>#include<stdlib.h>intMain () {inta,b,c,d,e,f,g,m,n,x; printf ("Enter your birthday, separated by commas \ n"); scanf ("%d,%d,%d",&a,&b,&c); printf ("Enter the current date, separated by commas \ n"); scanf ("%d,%d,%d",&d,&e,&f); if(b==1|| b==3|| b==5|| b==7|| b==8|| b==Ten|| b== A|| e==1|| e==3|| e==5|| e==7|| e==8|| e==Ten|| e== A)    {        if((c> to&&c<1)|| (f> to&&f<1) {printf ("error \ n"); Exit (0); }    }        Else if(b==4|| b==6|| b==9|| b== One|| e==4|| e==6|| e==9|| e== One)    {        if((c> -&&c<1)|| (f> -&&f<1) {printf ("error \ n"); Exit (0); }    }            Else if(b==2|| e==2)    {        if((c> in&&c<1)|| (f> in&&f<1) {printf ("error \ n"); Exit (0); }    }        Else{printf ("error \ n"); Exit (0); } m=a*10000+b* -+C; N=d*10000+e* -+F; X=n-m; G=x/10000; printf ("you are%d years old \ n", G); return 0;}

Results:

Summary: To be aware of the use of if and else, learn to terminate the program with exit (0)

Three, character judgment

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".

Code:

#include <stdio.h>intMain () {Charb; printf ("Enter a character. \ n"); scanf ("%c",&a); if(a>='a'&&a<='Z') {b=a- +; printf ("%c\n", B); }    Else if(a>='A'&&a<='Z') {b=a+ +; printf ("%c\n", B); }    Else if(a==' ') {printf ("space\n"); }    Else if(a>='0'&&a<='9') {printf ("%c\n", a); }    Else{printf (" Other"); }    return 0;}

Results:

Summary: To use char to save characters and spaces

Four, triangle

Requirements:

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

Code:

#include <stdio.h>intMain () {intA,b,c; printf ("Please enter the length of the triangular three sides \ n"); 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 \ n"); }        Else if(a==b&&b==c) {printf ("equilateral triangle \ n"); }        Else if((a*a+b*b==c*c) | | (b*b+c*c==a*a) | | a*a+c*c==b*b) {printf ("right triangle \ n"); }        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 \ n"); }        Else{printf ("General triangle \ n"); }    }    Else{printf ("non-triangular \ n"); }    return 0;}

Results:

Summary: To use good "| |" " && "and other symbols

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.