C-Sixth week assignment

Source: Internet
Author: User

Topic

Topic One: Expressway speeding penalty

1. Experiment Code

#include <stdio.h>intMain () {intSpeed,maxspeed; Doublex; scanf ("%d%d",&speed,&maxspeed); X=(Double) (Speed-maxspeed)/(Double) maxspeed* -; if(x<Ten) printf ("OK"); Else if(x>= -) printf ("exceed%.0f%%. License revoked", x); Elseprintf ("exceed%.0f%%. Ticket", x); return 0;}

2. Design Ideas

① algorithm

Begin

Input Speed,maxspeed//indicates actual speed and lane speed limit respectively

Calculates the value of x//x as a percentage of the actual speed beyond the lane speed limit

Determine the size of the X value and output different results

End

② flowchart

3. No problems encountered

4. PTA Submission List

Topic Two: Calculation of oil costs

1. Experiment Code

#include <stdio.h>intMain () {intA =0; floatB,price,discount,money; CharC; scanf ("%d%2f%c",&a,&b,&c); if(b = = -) { price=6.95; }    if(b = = the) { price=7.44; }    if(b = = the) { price=7.93; }    if(c = ='m') {Discount=0.05; }    if(c = ='e') {Discount=0.03; } Money= A * price * (1-discount); printf ("%.2f", Money); } 

2. Design Ideas

① algorithm

Begin

Input a,b,c//a for fuel, b for petrol, C for service type

Determine the value of B, define the value of price//By judging the different varieties of gasoline, define different unit prices

Determine the value of C, define the value of discount//define different discount ratios by judging different types of services

Calculate Money//Use Money = A * price * (1-discount) This formula calculates payables

Value of the output money

End

② flowchart

3. No problems encountered

4. PTA Submission List

Topic Three: Comparison size

1. Experiment Code

#include <stdio.h>intMain () {inta,b,c,x,y,z; scanf (" %d%d%d",&a,&b,&c); if(A >b) {x=A; Z=b; }Else{x=b; Z=A; }    if(C >x) {x=C; }Else{        if(C <z) {Z=C; }} y= a + B + c-x-Z; printf ("%d->%d->%d", z,y,x); } 

2. Design Ideas

① algorithm

Begin

Input A,b,c

Determine the size of the value of a and B, assign the larger value to X, and the smaller value to Z. Defines x as the maximum value, z as the minimum, and y as the middle value

determine the size of the value of the larger and C values in a and B. If C is large, assign C to x.

Otherwise, determine if C is less than the smaller value in a and B. If so, assign C to Z.

The median y is the sum of three numbers minus the maximum and minimum values.

Output z->y->x

End

② flowchart

3. No problems encountered

4. PTA Submission List

Topic Four: A simple calculator of two numbers

1. Experiment Code

#include <stdio.h>intMain () {intA,b,answer; CharC; scanf ("%d%c%d",&a,&c,&b); Switch(c) { Case '+': Answer= A +b; printf ("%d", answer);  Break;  Case '-': Answer= A-b; printf ("%d", answer);  Break;  Case '*': Answer= A *b; printf ("%d", answer);  Break;  Case '/': Answer= A/b; printf ("%d", answer);  Break;  Case '%': Answer= a%b; printf ("%d", answer);  Break; default: printf ("ERROR"); }    return 0;}

2. Design Ideas

① algorithm

Begin

Input a C B;//a, B is the input two integers, C is the operator

Determine why C is a symbol

If it is legal, calculate and output the results of A and B after this operator operation

If it is not legal, output error

② flowchart

3. In the first place, the switch statement was not used according to the job request, and the classmate reminded the amendment.

Initial if statement code:

#include <stdio.h>intMain () {intA,b,answer; CharC; scanf ("%d%c%d",&a,&c,&b); if(c = ='+') {Answer= A +b; printf ("%d", answer); }Else if(c = ='-') {Answer= A-b; printf ("%d", answer); }Else if(c = ='*') {Answer= A *b; printf ("%d", answer); }Else if(c = ='/') {Answer= A/b; printf ("%d", answer); }Else if(c = ='%') {Answer= a%b; printf ("%d", answer); }Else{printf ("ERROR"); }     } 

4. PTA Submission List

My git address: https://git.coding.net/dx200798/sixth.git

Project

Personal Summary

First, this week's study content:

1. Learn the three loop statements of the while statement, the Do...while statement, the For statement, and learn the nesting of three loops in each other.

2. Learn the break statement and the continue statement.

3. Practice the IF statement and the switch statement to improve the proficiency of the statement application.

Second, doubtful points:

There is no more proficiency in the for statement, but it also requires practice.

Thirdly, there is no opinion on the present form of the teacher's class and cannot offer any advice.

Mutual Assessment and learning progress

Cross-evaluation links

Link One:

Link two:

Link Three:

Chart

C-Sixth week assignment

Related Article

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.