C language I work 004

This work belongs to the curriculum C Programming Language II
Where the job requires C language I work 004
My aim in this course is Control loop structure of usage, learn to use the for statement
This job helped me achieve that goal in terms of specific Society loop structure, there are certain rules can solve some math problems
references Fourth Shift software code for assistant jobs

1.PTA lab assignments

1.1 (7-4) for calculating partial sequence and the inverse of the square of

Description Title: The title requires two positive integers m and n- ( mn- ) programming, and calculates the sequence m 2. 1 + / m + ( m + 1'd). 1 + 2 / ( m + 1'd) + ⋯ + n- . 1 + 2 / n- .

Input formats:

Input is given in a row two positive integers m and n- ( mn- ), separated by spaces therebetween.

Output formats:

And output portion of the value S in accordance with the "sum = S" format in a row, six decimal place. Title ensure that the calculation result does not exceed the double precision.

Sample input:

5 10

Sample output:

sum = 355.845635

1.1.1 Data Processing

Expression Data: This question defines variables i and n, respectively, for shaping two intermediate variables and parameters as input; also defines a double-precision floating-point variable sum as a final summation value, and defines the sum of the initial value = 0

Data processing: calculating sequence and m +. 1/2 m + ( m + 1'd). 1 + 2 / ( m + 1'd) + ⋯ + n- 2 +. 1 / n-

1.1.2 Screenshot experiment code

1.1.3 build test data

Input data Output Data Explanation
1 1 sum = 1 The minimum boundary
5 10 sum = 355.845635 同sample

1.1.4 PTA submit a list and description

Submit a list of instructions:

  • Format Error: i <= n is written at the i <= n; forget the space, resulting in malformed

1.2 (7-5) required interleaving sequence and first N

Description Title: The title requires programming, the sequence of staggered 1-2 / 3 + 3 / 5-4 / 7 + 5 / 9-6 / 11 + ... and the first N.

Input formats:

In a given input row positive integer N.

Output formats:

Value output portion and in a row, the results of three decimal places.

Sample input:

5

Sample output:

0.917

1.2.1 Data Processing

Expression Data: This defines the title i, n, flag three integer variables, intermediate variables I, as an n-input parameters, flag used to transform the expression sign, in addition to a double-precision floating point defined variable sum as a final summation value, and defines the sum of the initial value = 0

Data processing: the sequence of staggered 1-2 / 3 + 3 / 5-4 / 7 + 5 / 9-6 / 11 + ... and the sum of the first N

  • flag as the intermediate variable expression sign transform

1.2.2 Code Screenshot

1.2.3 build test data

Input data Output Data Explanation
5 0.917 sample, N is an odd number
6 0.372 even
1 1.000 Min Odd
2 0.333 Minimum even number

1.2.4 PTA submit a list and description

Submit a list of instructions:

  1. Wrong Answer: printf ( ".% 3f", sum);% .3f because the topics in the habit of thinking that it is in front of the sum =% .3f, so the result is output sum = 0.917, wrong answer.
  2. Wrong Answer: As above, the first change of position did not change

2. Code peer assessment

Screenshot students Code

Own Code Screenshot

difference

  1. Students in the middle of the eighth row of the code with the double forced conversion, cast him into a number of floating-point, and I am at the time of the input data on the direct use of real numbers
  2. He will accumulate in the denominator of the sum expression reclassified as accumulation operation had a formula denominator, I directly added to the sum expression in the denominator simultaneously accumulating process

3. learning summary

3.1 learning progress bar

week This week the time spent Lines of code Learned knowledge Introduction
Eighth Week 12 hours 110 for loop

3.2. Cumulative lines of code words and blog

time Words blog The number of lines of code
fifth week 828 0
Sixth Week 2985 372
Week Seven 4362 598
Eighth Week 708

3.3 Summary and perception of learning content

3.3.1 learning content summary

  • for loop: for (Expression 1; 2 Expression; Expression 3)

    Loop statement;

  • i ++ increment

3.3.2 Learning Experience

This week in the learning process went smoothly, did not encounter any particular difficulties point; but did not do that they want to develop the habit did not do it, who used to develop each write code to do good comment this week but failed to do so; at the same time with the local harvest, try the next contest that network security, though only made the first two questions, the latter do not move, it may be that we have not learned the web reasons for it, but still feel it something that understand the answer lies in the fact, sometimes the most obvious place, but you have to learn to find him, to have found good eye, which is useful for us after checking code.

Guess you like

Origin www.cnblogs.com/just-like-this/p/11693828.html