First, the PTA laboratory work title 1:6-5 use the function to output an integer in reverse order number 1. PTA Submission List
2. Design ideas (1) define the integer variable count,m,j,k the number of digits, the number value, the number of cycles, the digits of each digit number, and assigns the initial value Count=0,m=number (2) number=number/ 10,count++ (3) when number! =0 Repeat step (2) The number is a count of bits (4) k=1, loop execution count-1 times k=k
10 The number of digits to be calculated is the first of several, number=number+m%10
K flashbacks each digit number and adds up (5) to determine if the m/10!=0 is M=M/10 to ensure that each digit is performed as described above (6) When Count>0 is cycled (4) (5) and count--(7) Returns the value of Number 3. The debugging process encountered problems and PTA submission List of the status note. -1. There are 04321 types of answers in flashbacks. Workaround: Add conditional Judgment m/10!=0 before M=M/10 to determine if number is 0 end, if then go to 0 topic 2:6-8 Use the function to output Fibonacci in the specified range 1. PTA Submission List
2. Design ideas int fib (int n) (1) defines the integer variable i,result,f1,f2 the number of cycles, the end result, the Fibonacci number of the first Fibonacci, the Fibonacci number of the first two Fibonacci number (2 ) to determine whether the input number of n is 1 or 2, if the return 1 means Fibonacci number first and the second item are 1 (3) Result=f1+f2,f1=f2,f2=result (4) Loop execution N-2 Step (2) when n>=3 Implement each Fibonacci number equal to the sum of the first two (5) return resultvoid printfn (int m,int N) (1) Define integer variables a,count the number of items to hold the Fibonacci number and the judging interval [m,n] If there is a Fibonacci number, assign the initial value count=0 (2) a=1 (3) to determine the FIB (a) >=m, if True output fib (a) and count=1. Judge Fib (a+1) <=n, if True output whitespace (4) when fib (a) <=n Repeat steps (3) (5) to determine count==0, if true output no Fibonacci Number3. Problems encountered during debugging and PTA submission List situation description. -1. There is no answer when N=m: Judging the relationship between FIB (a) and m,n, use the >= or <= topic 3:7-1 to find the combination number 1. PTA Submission List
2. Design ideas (1) a double fact (int n) function declaration (2) defines an integer variable m,n holds a total of n different elements, takes m elements, defines the floating-point variable result holding combination number results (3) The value of the input m,n (4) result=1.0
fact (n)/(Fact (m)
Fact (N-M) calculates the number of combinations of m elements from n different elements and outputs (5) Defines the function double fact (int n) (6) defines the floating-point variable result store n! and assigns the initial value result=1 (7) to determine whether n is 0, if 0 is return 1; otherwise the loop executes N times result=result*n to find out n! (8) Return RESUL3. Problems encountered during debugging and PTA submission list status. 1. The output has a decimal solution: There is no answer when the output format is changed to%.0f2.n=m: To determine whether n is 0 in fact (N), or 0 to return 12, peer-to-peer evaluation 1. 2. My Code, peer-reviewed classmate code My Code: Wang Lincong Code: 3. What's the difference between me and my classmate's code? What are the respective advantages? What style of code do you prefer? Different points and pros and cons: My code first to find the operand is a few digits and then the nested loop structure in reverse order, variable, complex structure. and Wang Lincong's code only uses a variable n and a while loop to find the results, more intuitive and concise. I prefer the code of Wang Lincong classmates. Third, this week's topic set PTA Final ranking.
Iv. Study Summary of the Week 1. What did you learn? What data types are 1.1 C languages? Integer data, real data, character data 1.2 character type data need to be aware of the place? 1. When you swap the definitions and values of integer and char variables, the value range of the integer data is valid ASCII code 2. ' A ' and ' a ' are different character constants, ' 0 ' and 0 are constants of different types, the former are character constants, and the latter are integral constant 1.3 self-increment decrement operators? The order of operations for 1.++n is: Execute n=n+1 First, and then the value of n as the value of the expression ++n n++ the order of operations is: first the value of n as the value of the expression n++, and then execute n=n+12. The operands of the increment and decrement operators can only be variables, not constants or expressions 1.4 Operator precedence? Textbook p1321.5 C language which expressions? What do you do wrong in class, please analyze the reason here?
C Language Blog Job--function