C language | blog Park 08

This work belongs courses C Programming Language 1
Where this requirement in the job http://edu.cnblogs.com/campus/zswxy/SE2019-2/homework/9981
In this course aims Learn to write small programs
references "C Programming Language" "C Primer Plus"

1. PTA lab assignments

1.1 title name 17-1 ask digit integer and the sum of the digits

For a given positive integer N, the number of bits required it and the sum of the digits.

1.1.1 Data Processing

Data processing: defined integer variable n (the input value)

begin
the definition of the variable n-, I, SUM
I ← 0, SUM ← 0;
the while (n-not 0);
{
SUM = SUM + n-% 10;
n-= n-/ 10;
I ++;
}
when n = 0, output i , SUM.
}
End

Data are expressed: Use the while statement into the loop. When n ≠ 0, using the expression sum = sum + n% 10, n / = 10 calculates the sum of the digits, i ++ increment bits and the calculated integer; and when n = 0, out of the loop.

1.1.2 Screenshot experiment code

1.1.3 build test data

Input data Output Data Explanation
321 3 6 Does not exceed 10 ^ 9 positive integer
2345 4 14 Does not exceed 10 ^ 9 positive integer
111111111111 12 -47 N is an integer of more than 10 ^ 9

1.4PTA submit a list and description

Submission Instructions
  1. Compile Error: No variable i, the initial value of the sum is assigned to 0; not equal to the arithmetic operators sloppy writing errors.
  2. Compile error: Call to a mathematical function, not a member of "#include <stdio.h>" The corresponding header file that contains the source code to go.

    1.2 2 title name crawling worms

    A length of 1 inch worm, the bottom of an inch deep N well. The worm is known inch per minute to climb U, but must then rest for 1 minute to climb. During the break, the worm has dropped D inch. In this way, climb and glide repeated.

    1.2.1 Data Processing

    Data processing: defined integer variable n, u, d.

begin
input variable S =. 1, n-, U, D, COUNT = 0;
do
{
(accumulation crawling height worms) S + = U;
Time ++;
S ← SD (declining rest worm height);
IF S> = n-then out of the loop, the Output Time;
the else statement to continue to continue to do the loop;
End

Data representation: using do-while, if-else statements.

1.2.2 Code Screenshot

1.2.3 build test data

Input data Output Data Explanation
12 3 1 11 Climbed out of the well 11 minutes
34 5 1 17 Climbed out of the wells 17 minutes
27 4 8 no data D> U illogical

1.2.4 PTA submit a list and description

Submission Instructions
  1. Compile Error: No sort out the meaning of the questions s (high-crawling worm also assigned to 0, with the head of the worm reached the top of the well, then the worm to complete the task, improper data processing) and logic errors.
  2. Compile error: do-while loop statement clerical error abort condition, also written as "(s <= n)", and the logic errors.
  3. Compile error: arithmetic operators "+ =" (the value of the right is applied to the left side variable) memory errors.
  4. Compile Error: scanf statement output data type discourse forget to add a semicolon.
  5. Compile error: nested loop conditions are not in place to write, a sense of logic errors.

    Code peer assessment

    Students Code

Own Code

  • Students from the code lines of code than I see no concise. However, the number of bytes of code to see a lot more than I want to be brief.
  • I just divided the average year, a leap of two parts of the number of days to be calculated, the program calculates carried out by non-leap year, leap year cumulative number of days of each month, the number of days each month to be calculated manually when writing code. Cumbersome trouble.
  • The students are, above all, common year or a leap year, and then the program depending on the month of May with the year determines whether the input.
  • From the simplicity of the code point of view, master swith statement of the student well, data processing in place, clear and intuitive.

    3. learning summary

    3.1 learning progress bar

    Week / Date Time spent Lines of code Learned knowledge Introduction Currently more confusing issues
    W7 15h 198 Data type Double Double precision floating point type; arithmetic operators; if-else statement selection structure like Common types of difference data
    W8 10h 87 Through the bad configuration, the arithmetic operators increment operator The priority order of the operators
    W9 10h 89 Function declaration, defining and calling Substantive difference parameter, argument
    W10 10h 112 Are familiar and can use a multi-branched structure and the if statement mosaic, character data types and logical operators Mosaic of various types of usage statement
    W11 12h 145 Use a switch statement to handle multiple branches problem, master switch statement What is the classification of multi-branch deal in place, how to be more concise statement
    W12 11h 81 A while, do-while loop statement to achieve programming Accurate expression while, do-while loop statement, a loop statement

    3.2 Cumulative lines of code words and blog

3.3 learning content summary

3.3.1 learning content summary

  • while for loop checks are performed before the loop loop condition is satisfied, the loop is performed to meet. The do-while loop is executed only after the loop checks whether the loop condition is also satisfied.
  • When the cycle involves initialization and update for use for loop variables.
  • Value cycle tests are required before the first use initialization. Expression with for relational operators Chang cycle test.
  • (+ = The value of the remainder is added to the right of the left variable, / = the variable of the left by the value of the right side, the left variable by right =% worth to): Logical Operators

3.3.2 Learning Experience

  • When this week to explain the operation last week, various big brother coming out "Wild World." Full of admiration full of envy. Small place I want to work too much.
  • So when things are make do with the need to complete and rational allocation of time is particularly important. Things outside this week to learn more, there is no good to do a reasonable allocation of time to carefully learn from the experience in the process of moving forward.
  • After-school C language self-study, practice is very important. . .

Guess you like

Origin www.cnblogs.com/tizipei/p/11857429.html