Third assignment.

Source: Internet
Author: User

1-1 character judgment

#include <stdio.h>intMain () {CharC; scanf ("%c",&c); if(c>='a'&&c<='Z') {C=c- +; printf ("%c\n", c); }    Else if(c>='A'&&c<='Z') {C=c+ +; printf ("%c\n", c); }    Else if(c>=0&&c<=9) {C=C; printf ("%c\n", c); }    Else if(c==' ') {printf ("space\n"); }    Else{printf ("other\n"); }    return 0;}

Knowledge Point Summary: Payment input/Output function Description: Output a character to the standard output system; C can be a character, a variable or an expression, or an integer data. If C is an integer data, the output ASCII value is the character of the integer data. When you use this function, you must include the header file Stdio.h in the beginning of the program, expressed as #include<stdio.h>.

Experimental Summary: Characters in single quotes, English case sensitivity remember ' a '--65, ' a '--97, ' 0 '--48, ' \ n '--10, and remember to use Exit (0) When forced exit is required;

1-2 years of age

#include <stdio.h>intMain () {inta,b,c,d,e,f,g; printf ("Please enter a student's birthday. \ n"); scanf ("%d%d%d",&a,&b,&c); printf ("%d years:%d months:%d days", A,b,c); printf ("Please enter the current date. \ n"); scanf ("%d%d%d",&d,&e,&f); printf ("%d years:%d months: &d Day", d,e,f); if(b==e&&c>f) {g=d-a-1; printf ("The student's birthday is%d years old", G); }    Else if(b==e&&c<=f) {g=d-A; printf ("The student's birthday is%d years old", G); }    Else if(b<e) {g=d-A; printf ("The student's birthday is%d years old", G); }    Else{g=d-a-1; printf ("The student's birthday is%d years old", G); }    return 0;}

Knowledge Point Summary: input and output to uniform format, printf when adding comments, but in the program does not run, to master the If...else statement.

Experimental Summary: Note that when the output to the "G" to give the conditions, because the program has not stressed the meaning of G, so in the output should remember to mark the same as the form of the problem, example: g=d-a; then in the output.

1-3 Judging the triangle type

#include <stdio.h>intMain () {intA,b,c; printf ("Please enter three integers to determine the type of triangle it consists of. \ n"); scanf ("%d%d%d",&a,&b,&c); if(a+b<c| | Fabs (A-B) >c) {printf ("The shape is non-triangular. \ n"); }    Else if(a*a+b*b==c*c) {printf ("the graph is right triangle. \ n"); }    Else if(a==b==c) {printf ("the graph is equilateral triangle. \ n"); }    Else if(a==b&&a*a+b*b!=c*c) {printf ("the graph is isosceles triangle. \ n"); }    Else if(a==b&&a*a+b*b==c*c) {printf ("the graph is isosceles right triangle. \ n"); }    Else{printf ("The shape is a triangle. \ n"); }    return 0;}

Knowledge Point Summary: Absolute value with fabs function, the equivalent of "= =".

Experimental summary: Analysis of the conditions of the occurrence of a good situation, should be consistent with the format, re-coding, the emphasis on the knowledge point of two points.

1-4 Guess the price

#include <stdio.h>#include<time.h>intMain () {intA,b,c; A=rand ()%Ten+1; printf ("This product is%d, guess its price \ n");    Srand (a); b=rand ()% -+1; printf ("Enter your answer \ n"); scanf ("%d",&c); if(b==c) {printf ("The product belongs to you, the answer is%d\n", B); }    Else if(c>b) {printf ("too big, the answer is%d\n.", B); }    Else{printf ("It 's too small, the answer is%d\n.", B); }    return 0;}

Knowledge Point Summary: Pay attention to the randomness of the program, consider the full implementation of the conditions, the expression to be correct, sub-situation.

Experimental summary: The use of head files, can be used in a more convenient form of coding, to be skilled use.

Third assignment.

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.