Branch and sequential structure

* 0.PTA score

1. This chapter summarizes the study

1.1 learning content summary

1. A program can only have a main () function, the program starts to run from
the front 2. variables must be defined, for example, X int
3.int storing integer data, float, and double floating-point data storing, a corresponding input format are scanf ( "% d", & variables) scanf ( "% f", & variables) scanf ( "% lf", & variables)
4. mathematical function to declare when calling the include # <math.h>
. 5. common mathematical functions square root function sqrt (x), the absolute value function fabs (x), power function pow (x), an exponential function exp (x), to the base e of the logarithmic function log (x), etc.
6. call input and output functions use #include <stdio.h>
going to pieces around-the else if statement after use relational expression, the expression is not an assignment. For example, if (x = 2) is incorrect, if (x == 2) is right
behind else 8.if-else statement relational expression can not be added
only after a statement 9.if and then else statements, if a plurality of statements to use braces
10. string variables when defining a char, and in the format illustrated as the call control C%, Scanf ( "% C", & CH);
11.getchar () and has a character is read only, putchar () may output a character
12. the use of a logical expression:
IF (a == C == a && B) IF (a == C == a || B)

1.2 Learning Experience

1.2.1 due to weak basic computer, just get started when the more difficult, difficult to understand the implementation of the program, just started to play the code shining textbook fight, fight with the increase in the amount of code, can understand the feeling. When do some relatively simple subject can also be handy, but many errors occur when confronted with problems, such as syntax errors.
Topic arranged on 1.2.2PTA 450 lines of code, plus their own multi-channel PTA 30 600 lines of code and new topics to do cycling title, a total of more than 1,400 lines of code

2.PTA lab assignments

Three small to large number of output 2.1

2.1.1 Data Processing

Data are expressed: the definition of a, b, c, x, y, z six variables, x, y, z is a variable requirements of the subject, a, b, c is a number from three inputs of integer variables are
data processing : judgment condition with a logical expression and nested if-else statements

2.1.2 Code FIG.


2.1.3 submit a list and description


Only one submission will be successful, this problem just started thinking mess, so I put the whole subject of process modifications on paper, straighten out a lot of ideas found in the process of writing

2.2 calculate the number of days

2.2.1 Data Processing

Data are expressed: Defines the month, year, day, day1 four variables are integer variables, consider that there might be less than a full month's case, the day1 to store, for example 2019/10/1, then day1 = 1
data processing: if-else statements or the use, the condition is determined individually calculated

2.2.2 Code FIG.


2.2.3 submit a list and description


Compile error is due to scanf often ignore the first variable to add & answer wrong because of this problem I used to answer mathematical laws, found that when the month is odd, the number of months 31 days = (current month -1) / 2,30 = the number of days the month (the current month -3) / 2; February is an even number, the number of the month = 31 days current month / day 2,30 = number of months (the current month -4) / 2, there is an error in the discovery process of the law , resulting in erroneous answers

2.3 the number of positive and negative numbers

2.3.1 Data Processing and Expression

Data are expressed: defines a variable i, j are stored the number of positive and negative
data processing: each of the inputted number is determined by the while statement and the statement with the break out

2.3.2 Code FIG.


2.2.3 Extended

Not only can be used to calculate the number of integers and negative, can also be used to calculate an arbitrary number larger than the number of conditions may be changed (number> a), or counting the number of leap year, the condition may be changed if ((number% 4 == 0 && number% 100! = 0) || (number% 100 == 0))

2.3.4 submit a list and description


The answer is because there is no error in the input loop statement scanf ( "% d", & number); cause can not enter more than one number, the compiler errors are often due to the wrong scanf format, found in vs debugging

3. Read Code


The code input object is to calculate a sum of ones digits integers, allowing the calculation of an integer of an integer number of bits in addition to the constant 10, and plus loop while, when the last 10 is equal to the number of other 0:00, the end of the cycle. Also learned n = n / 10 can be abbreviated as n / = 10 in the form of other similar calculation.

Guess you like

Origin www.cnblogs.com/sym2446/p/11619709.html