First, the PTA laboratory work Title 1:6-2 Simple implementation of X's n-th square 1. PTA Submission List
2. Design ideas (1) define the function Mypow (double x, int n) (2) Define the integer variable i is the loop variable, the floating-point variable sum is the product of the factorial (3) for I=1 to n repeat the following step (4) Calculation sum=sum*x (5) Returns the value of Sum 3. The subject has been debugged. Process encountered problems and PTA submission List status note
The initial code is this: the commit error is a segment error
The next day genius roommate told me to use a for loop and a factorial variable, and then I added a for loop, but it wasn't correct, because my return value was not correct, and the sum was not assigned a value, the error code is as follows:
She looked at my code helpless explanation, the problem does not have to output, the variable has been defined no longer defined, again corrected, or not correct, and then start debugging, running and debugging process as follows:
No matter how much I sum is always 0, then it is correct to define sum as a floating-point type, the correct code is as follows:
Step by step down to find your code in the correct code 108,000, do not know with a for loop, do not redefine the new variable, no assignment, output and return value is also a mess, I do not quite understand what the return value is, why to return? And how do I return it? Return to Who?
Topic 2: Use the function to determine the total square number 1. PTA Submission List
2. Design ideas (1) function Interface definition int issquare (int n) (2) int i put loop variable, m put an integer of input, M put full square number (3) Assignment value M=1,m=1 (4) input an integer M, when I<=m, repeat loop (5) if m*m==m , returns 1, otherwise returns 03. Problems encountered in debugging process and PTA Submission List status note
Initial code:
Compile to enter more than two data, but only one data can be recognized, either the previous yes, or the back of no, as shown in
PTA Submission list is partially correct, according to the hint seems to be less consider the case of M negative, but changed to change to a compilation error
Topic 3:400~499 4 Occurrences of the number of 1. PTA Submission List
2. Design ideas (1) int integer, I put the loop variable, count put 4 number of times, single digit number, ten put 10 digits, hundred put hundreds of numbers (2) respectively for the value of 10 digits, single=x%10; The integer takes the remainder to obtain the single digit//ten=x/10%10; Besides 10 the remainder gets 10 digits//hundred=x/100; Divide by 100 to get the number of hundred//(3) Bits for 4, 10 and hundred are not 4, 10 bits is 4, the digit and the Hundred is not 4, the Hundred is 4, the digit and 10 bits are not 4, then 4 appears 1 times (4) Bits are 4, 10 bits and hundred is 4, 10 bits are not 4, the digit and the Hundred is 4, the Hundred is not 4, The digit and 10 bits are 4, then 4 appears 2 times (5) digit 10 bit hundred is 4, then 4 appears 3 times (6) digit 10 digit hundred is not 4, then 4 appears 0 times (7) returns COUNT3. Problems encountered in debugging process and PTA submission list information
The first time did not carefully check the symbol punctuation and other details caused the compilation error, the second is the answer error, because did not consider the situation of count=0, and did not add count after each if, after the completion of the correct, the code process is as follows:
Topic 4: Finding the number of combinations 1. PTA Submission List
2. Design ideas (1) int m,n; double result; (2) Input m,n (3) Call function to find factorial fact (n); Fact (M), fact (N-M), (4) Calculation of the result by formula Result=fact (n)/(Fact (M) *fact (N-M)), (5) result = Combinatorial number calculation results "output (6) The definition of combinatorial number function (7) int i is a cyclic variable, The double sum implements the multiplicative (8) when i<n, repeats the Loop, Sum=sum*i (9) returns SUM3. Problems encountered during debugging and PTA submission List (1) Call the function to find the factorial when only one call, not the sum assignment, (2) The calculation of the result =fact (n)/(Fact (M) *fact (N-M)) did not enclose the division sign behind, resulting in a large number of results (3) The definition of variables is too much to think of as complex, so there are many cyclic variables defined (4) result =%.0f and result =%f difference
Second, peer code pairs of peer review 1. Peer Reviews Photos
2. My Code, mutual evaluation of the student code
My Code:
Ya Hui's code:
3. Where do I differ from my classmates ' code? What are the advantages? What style of code do you prefer? I and Ya Hui code different in my more, her less my advantage is the variable defined more than her details, her advantage is the code is less, clear, she used a for loop, and I did not I like her style, but her code I do not understand, my I understand the third, the last of the topic set of PTA Final ranking
Iv. Study Summary of the Week 1. What did you learn?
The data types of the C language are integer, floating point, and character type.
Character data can not be random space, because the space is also counted as a character
The operand of the self-increment decrement operator can only be a variable, cannot be a constant or an expression, n++ and n--are equivalent to n=n+1, but the n++ order of operations is the value of the value of n as the expression n++ first, and then N=n+1,++n is performed n=n+1, in the value of n as an expression + The value of the +n. n--and--n.
2. This week's content, you are not what?
binary, decimal and hexadecimal, complement code, operator and expression, L for example, a+=a-=a*a is always wrong.
3. Circular structure Examination Summary 1. What is wrong and how to change it?
A problem is not done right, do not know how to do all
2. is the exam result satisfactory, how to improve?
Not satisfied, or learn not Ah, who can teach me how to improve
C Language Fifth Blog job--function