Homework (i)

Source: Internet
Author: User

First question one:

1. Experimental requirements: programmed to print 5 rows of inverted triangles, the first line to print 9 *, the second line 7 *, ... Line 5th Print 1 *

2. Code:

#include <stdio.h>intMain () {printf ("*********\n"); printf ("******* \ n"); printf ("* * * \"); printf ("* * \ n"); printf ("* \ n"); return 0;}

3. Program Operation Result:

4. Experiment Summary: Each line of ";" Can't forget

The second question:

1. Experimental Requirements:

Enter 3 integers and calculate their and,

Input format: 1 2 3

Output format: 1+2+3=6

2. Code:

#include <stdio.h>int  main () {    int  a,b,c,d;    printf (" Please enter three digits (separated by a space): \ n");    scanf ("%d%d%d",&a,&b,&c);    D=a+b+C;    printf ("%d+%d+%d=%d\n", a,b,c,d);     return 0 ;}

3. Program Operation Result:

4. Experiment Summary: separated by "space", and not less ";".

Question three:

1. Experimental Requirements:

Enter and output data according to the following format requirements

Output: Please enter today's date, month and year daily comma separate

Input: 2016,9,13

Output: Please enter your birthday, format: year-month-day

Input: 1998-5-6

Output: You are 18 years old, your birthday is 1998-05-06

2. Code:

#include <stdio.h>intMain () {inta,b,c,d,e,f,g; printf ("Please enter today's date, year and month daily Comma separated \ n"); scanf ("%d,%d,%d",&a,&b,&c); printf ("Please enter your date, format: year-month-day \ n"); scanf ("%d-%d-%d",&d,&e,&f); G=a-D; printf ("you're%d today, and your birthday is%d-%d-%d\n .", g,d,e,f); return 0;}

3. Program Operation Result:

4. Experimental summary: The date of the separate format, as well as curly braces up to two is not missing one.

Question Fourth:

1. Experimental Requirements:

Read three integers to a,b,c, then swap the numbers in them, give the original value in a to B, give the original value of B to C, give the original value of C to a, and finally output the value of A,b,c.

2. Code:

#include <stdio.h>int  main () {    int  a,b,c,d;    printf (" Please enter three integer ABC, and separate \ n");    scanf ("%d,%d,%d",&a,&b,&c);    D=a,a=b,b=c,c=D;    printf ("a=%d,b=%d,c=%d\n", a,b,c);     return 0 ;}

3. Program Operation Result:

4. Experiment Summary: Note that the equals sign is right to give the left value, and pay attention to the order.

Question Fifth:

1. Experiment requires: Enter X minutes to convert minutes to hours and minutes. If you enter 150 minutes, the output format is: 150 minutes = 2 hours 30 minutes.

2. Code:

 #include <stdio.h>int   main () {     int   A,b,c; printf (   Please enter the number of minutes: \ n   " ); scanf (  %d     , &a); b  =a/60 , C=a%60  ; printf (   " ,a,b,c);  return  0  ;}  

3. Program Operation Result:

4. Experiment Summary: Note the difference between dividing and taking the remainder.

Question sixth:

1. Experimental requirements: Programming input a four-bit integer n, the reverse number of Nr. The required output should also be a four-bit integer. If you enter 3720, the output should be 0273.

2. Code:

#include <stdio.h>intMain () {inta,b,c,d,e,f; printf ("Please enter a four-bit integer n:\n"); scanf ("%d",&a); b=a/ +, c=a% +/ -, d=a% +% -/Ten, e=a% +% -%Ten; F= +*e+ -*d+Ten*c+b; printf ("the number of flashbacks in%d is%04d\n", a,f); return 0;}

3. Program Operation Result:

4. Experimental summary: Maintain four-digit integrity, note that the number of digits is 0, the first digit of flashbacks should also be 0.

Question seventh:

1. Experiment requirements: The radius of the input circle, the circumference of the output circle and the volume of the sphere formed around the diameter, the result is reserved two decimal places.

2. Code:

#include <stdio.h>#definePI 3.1415926intMain () {floatr,l,v; printf ("Please enter the radius of the circle: \ n"); scanf ("%f",&R); L=2*pi*R; V=4.0/3.0*pi*r*r*R; printf ("The circumference of the circle is l=%.2f, and the volume of the sphere formed around the diameter is v=%.2f\n", l,v); return 0;}

3. Program Operation Result:

4. Experiment Summary: Note the decimal point of four-thirds, and retain two decimal places.

Homework (i)

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.