C language I- blog work 04

This work belongs to the curriculum C Programming Language II
Where the job requires C language blog I work 04
My aim in this course is Master cycle program designed to be used for loop to achieve a specified number of times
This job helped me achieve that goal in terms of specific Gradually utilized in the preparation of the code
references Blog work 04 operational requirements

A, .PTA experimental work

Pursuit of 1.1 minutes and a first N odd sequence

This problem requires programming, calculates the sequence 1 + 1/3 + 1/5 + ... and the first N.

Input formats:

In a given input row positive integer N.

Sample input:

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:

Sample output:

1.1.1 Data Processing

  • Data are expressed: the answer using the variable integer int n, float double sum variable
  • Data processing: source used as a basic framework, a for loop uses to run the expression sum = sum + 1.0 / (2.0 * i-1.0);

    1.1.2 Screenshot experiment code

    1.1.3 build test data

    Input data Output Data Explanation
    45 sum = 2.885097 Greater than 0
    -1 sum = 0.000000 Less than 0
    0 sum = 0.000000 Equal to 0

    1.1.4 PTA submit a list and description

    Submit a list of instructions:

  • Wrong Answer: never found the wrong answer has not led to the expression, behind almost twists and turns finally corrected.

    1.2 seeking interleaving sequence and first N

    This requires programming problem, 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:

    Sample output:

    1.2.1 Data Processing

  • Data are expressed: The title uses the variable integer int i, n and double floating point variable variable sum, sign;
  • Data processing: source using a frame function, loop by loop for expression: Sign POW = (-1,. 1-I);
    SUM = SUM + (I Sign) / (2.0 I-1.0); N items calculated with.

    1.2.2 Code Screenshot

    1.1.3 build test data

    Input data Output Data Explanation
    40 sum = 2.826208 Greater than 0
    20 sum = 2.479673 Greater than 0
    -1 sum = 0.000000 Less than 0
    0 sum = 0. 000000 Equal to 0

    1.1.4 PTA submit a list and description

  • Editorial errors: forget the semicolon hit;
  • Wrong Answer: The expression has been wrong not write, repeatedly running different expressions, finally found the problem, the output does not need to write "sum =";

    Second, the code peer review

    Students (Fuxiang Liang) Code Screenshot

    Students (music tree text) Code Screenshot

    I screenshot

  • (1) The first piece of code (pay students) and second codes (music students) not a big difference, because the title bar is relatively simple, so the code is relatively simple, little difference is that music students Shuwen code is an initial sum 1, and the code Fuxiang Liang students initial sum to zero, the students pay for the code to be run more than once, but the answer They also expressed six digits # slightly different retention after the decimal point, the students pay is sum =% f, and Music students are using sum =% .6f, although the same meaning, but Road to Jane it;
  • (2) The first copy of the code and my code difference is that I write a lot of useless code, such as the beginning of the #include <math.h> int back and separated by, but also with a double variables did not set up a with the sign, are they useless;
  • (3) The second code is not very different from the first, and so my difference with the second analysis of the same, in general, my code the most complex, but relatively easy to change.

    Third, learning summary

    3.1 learning progress bar

    Week / Date This week the time spent Lines of code Learned knowledge Introduction Currently more confusing issues
    Week Seven 10 hours 132 line Common mathematical functions, if-else statements Function for operation
    Eighth Week 13 hours 156 line Learn to use a for loop and know DevcC ++ debugger For DevcC ++ or not the General Assembly with

    3.2 Cumulative lines of code words and blog

    time Words blog The number of lines of code
    fifth week 464 0
    Sixth Week 1017 50
    Week Seven 1638 185
    Eighth Week 2533 341

    3.3 Summary and perception of learning content

    3.3.1 learning content summary

  • This week learning and the use of the for loop in DevcC ++ debugging and coding;
  • for loop mainly for the line, first for (initial assignment to write cycle; end of cycle condition; expression when the cycle)
  • Also the use of loops for a specific number of times is not, a program can be used for a loop, several may be used in conjunction;
  • Use DevcC ++ debugger, must first determine statement has no syntax problems, then slowly add conditions to gradually correct the wrong tune.

    3.3.2 Learning Experience

  • This week learning the for loop, comparing the if-else statement last week, a little more complicated, but not a big problem;
  • The main feeling is that work time is getting short, has gradually improved operational requirements of our own technical content improved a lot;
  • PTA jobs can be pre-compiled C language simulator DevcC ++ no problem and then copy and paste the past, you can submit a lot less errors, reduce the work load;
  • I also understand that the preparation of the code, ah, more than a mere compilation of code, have to think about how you want to run out of answers, mainly due to the difficulty of the job promotion, not a single answer.

Guess you like

Origin www.cnblogs.com/pengjie20199484/p/11699753.html