PTA Experiment report (loop array function)

Source: Internet
Author: User
Tags square root value of pi

I. CYCLIC PTA LAB Operation

Topic one. 7-2 finding the square root sequence of the first N and

1. PTA Submission List

2. Design Ideas

The subject calls the SQRT mathematical function to calculate the square root, followed by only a layer of loops, calculates the square root after the sum sum is calculated using the cyclic summation.

The middle value item is used to receive the square root value of each time, and then it is added to sum.

The procedure is straightforward and easy to use for loops.

3. Problems encountered in debugging process and PTA Submission List situation description.

(1) The For loop uses an error.

Because the For statement only controls a statement immediately following it,

And in the first commit, no brackets are added to the For statement,

There is no loop around the for statement, which results in an answer error.

(2) Format error.

PTA is a very rigorous platform, this error I looked for a long time after the classmate's reminder that the output when the format is wrong.

In the output when the sum should be added a space, "=" should also be added a space, so that the re-submission is right.

This error alert oneself must follow the topic request to do, must read the topic carefully.

4. Code.

Topic two. 7-7 calculating factorial

1. PTA Submission List

2. Design Ideas

The subject uses a two-layer loop.

The outer loop is used to accumulate each factorial in sum, and the inner loop is used to calculate the factorial value recorded in item.

In the outer loop, it is important to assign an initial value to each item so that the last item value still exists and the answer is wrong.

Outer Loop and inner loop nesting use is an important knowledge point about loops.

3. Problems encountered in debugging process and PTA Submission List situation description.

The problem because in Dev in the modified run the direct copy paste on the PTA, so there is no big error.

The following error occurred in Dev due to carelessness:

After the examination, it was found that the letters were spelled incorrectly. A lot of similar mistakes have been made since then, and it concludes that the errors are generally due to misspelled words.

4. Code.

Topic three. 7-32 for 1 to 100 and

1. PTA Submission List

2. Design Ideas

Use a layer of loops to accumulate one to 100, stored in sum, and then output.

The subject is relatively simple circulation body, but should be careful to do.

3. Problems encountered in debugging process and PTA Submission List situation description.

(1) The answer is wrong as a result of carelessness.

The subject just started to submit the error, I have been looking for a long while did not find out the error, in Dev also no hint.

Again submitted the second or the answer is wrong, I looked for a classmate to help me to find the error, the printf statement error occurred.

printf ("sum =%d", &sum);

Sum should not be added before the &, because careless hit up, in the search for errors wasted a long time.

So, in the future when playing code must be careful, on the one hand for correctness, on the other hand to prevent wasting time.

Second, peer code peer evaluation

1. Mutual evaluation Students: Zhu Jianan

2. My Code, mutual evaluation of the student code

Zhu Jianan The code of the classmate:

My Code:

3. What is the difference between my Zhu Jianan and my classmates ' code? What are their strengths? What style of code do you prefer?

The difference is that Zhu Jianan students use a while loop, and I use a For loop.

Their advantages: Zhu Jianan's code is more concise, in the definition of the variable only use a letter, so the error rate is very low. If the name of the variable is too long in the definition of the variable, it can cause a lot of time to be wasted in the subsequent error-checking.

I prefer the code of Zhu Jianan classmates.

Third, this week's topic set PTA Final ranking.

Iv. Summary of this week's study (2 points)

1. I learned the simple loop structure to write a program, and also mastered some of the use of nested loops.

2. This week's content, you are not what?

If the program requires three or more than three loop structure will be a little hard, some problems will not be written.

such as 7-28 7-31 7-34 and other topics will not be written.

3. Circular Structure Examination Summary

(1). Which problem is wrong, how to change it?

7-6 the problem is a partial error.

The specific reason is not yet known. Be prepared to ask a few more classmates or teachers to see how to modify.

(2). Are you satisfied with the exam results, how to improve?

More satisfied, try to be good.

I want to read more books and more dozen code.

Two. Array of PTA Lab work

Topic one. 7-1 array elements cyclic right shift problem

1. PTA Submission List

2. Design Ideas

Use an array to store a sequence of numbers, and then use the properties of the array to complete the topic requirements.

The subject did quite a long time, just began to want to use a cycle to complete the right shift, no matter how kind is wrong.

Then think about it, it is easier to use two loops to move right.

Use the inner loop to complete the right shift once, and then use the outer loop to achieve the problem required by the loop right shift n times.

And in the inner loop, it is easier to use decrement than to accumulate, to accept the value of a[n-1] with item, and to assign the value of item to the new constituent array's a[0] at the end of the inner loop.

3. Problems encountered in debugging process and PTA Submission List situation description.

(1). Segment error.

I didn't know where it was wrong at first. Later through the search to know the paragraph error is generally reserved for the system of space is not enough to the size of the required storage space.

The first definition of the integer array a[10], and later changed to a[100] is correct.

In fact, after learning the dynamic allocation of space, if the use of dynamic allocation of space will not have such a problem.

(2). After the topic is completed, I would like to try to use the cumulative way in the inner loop instead of decreasing the way to achieve the right shift once, found that it is troublesome and the answer is wrong, and ultimately the use of a diminishing way.

4. Code.

Topic two. 7-4 finding integers

1. PTA Submission List

2. Design Ideas

Use an array to store n integers, then use a for loop in the array to find the number equal to X, and if found, output its subscript i in the array and exit the loop.

If not found, output "not Found".

3. Problems encountered in debugging process and PTA Submission List situation description.

There is not much error in the subject, and some minor errors have been copied directly to the PTA after debugging on Dev.

In the process of drawing a flowchart, it is found that the flag defined in the code can be omitted, the value of x is found in the direct output subscript and then exit the loop, if not found, I value has been accumulated, when the accumulation of n when the direct output "not Found", there is no need to flag the existence of the code will be very concise.

4. Code.

Topic three. 7-10 matrix operations

1. PTA Submission List

2. Design Ideas

The subject uses a two-dimensional array, which is the most important part of the array application.

Using a two-dimensional array to enter an n-order matrix, use the properties of the array, and then use the For loop to calculate the sum of all the elements except the diagonal, the last column, and the last row of the matrix, summing up in sums, and finally outputting the value of sum.

3. Problems encountered in debugging process and PTA Submission List situation description.

(1) Break use error.

The first time the IF statement is used to determine if it is a diagonal element, and if it exits the loop, this results in an answer error.

Later after discussing with the classmate did not use the break statement, using the IF statement, if added to the sub-diagonal element, the value of sum is unchanged, that is, the statement sum=sum. The answer is correct.

4. Code.

Second, peer code peer evaluation

1. Mutual evaluation Students: Wang Huiting

2. My Code, mutual evaluation of the student code

Wang Huiting The code of the classmate:

My Code:

3. What is the difference between my Wang Huiting and my classmates ' code? What are their strengths? What style of code do you prefer?

The difference is that the Wang Huiting code is to add up all the elements except the last and last row of the matrix, minus the elements on the sub-diagonal.

And my code is sort of summed up.

Respective advantages: Wang Huiting The code of the classmate used another way of thinking to make the code more concise.

I prefer the code of Wang Huiting classmates.

Third, this week's topic set PTA Final ranking.

Iv. Summary of this week's study (2 points)

1. I learned a simple array to write a program, and also mastered the use of some two-dimensional arrays.

2. This week's content, you are not what?

If it is a simpler two-dimensional array program I can also better complete, a little bit difficult to complete the two-dimensional array when it is difficult.

There are many questions that will not: 7-5,7-7,7-8,7-9,7-11,7-13,7-15,7-16,7-17,7-19,7-20,7-23,7-24,7-25,7-27,7-28,7-29,7-30

3. Array Exam Summary

(1). Which problem is wrong, how to change it?

7-17 the problem is a partial error.

The specific reason is not yet known. Be prepared to ask a few more classmates or teachers to see how to modify.

(2). Are you satisfied with the exam results, how to improve?

Not satisfied, there are many problems did not do, hope that they have time to do.

Three. Function PTA Experiment Work

Topic one. 7-1 Combinatorial number

1. PTA Submission List

2. Design Ideas

The subject uses two function call structures.

The first ans (y,z) function is called to simply implement the formula calculation of the combinatorial number, which in turn stores the result in ANS and the final return value.

?? The second fact (x) function is called to calculate the simple factorial in the calculation of the ball combination number formula, use the function when calculating the factorial, allow the code to reuse the sub-function calculation, and then store the results in JC, and finally return the value.

The invocation of two functions makes the code simple and clear, which reflects the importance of the function application.

3. Problems encountered in debugging process and PTA Submission List situation description.

(1). function type definition error.

The topic explicitly requires that the fact function of the calculation factorial is of type double, and I am careless to define its type as int, resulting in a partial error in the answer.

And in the commissioning of a lot of wasted time, repeated submissions many times.

4. Code.

Topic two. 7-3 Sum of exponentiation

1. PTA Submission List

2. Design Ideas

Ontology is a relatively simple topic of function invocation.

The Call function mi (n) calculates the sum of the power of 2, which simply implements the summation of the power of 2 in the sub-function, and then stores the accumulated value in sum, and finally returns the value.

3. Problems encountered in debugging process and PTA Submission List situation description.

The problem because the dev has been debugged on the direct copy on the PTA, there is no error.

But in the dev debugging I found myself still very careless, some statements do not have semicolons, letters, such as spelling mistakes and so on, or to practice, but also more careful.

4. Code.

Topic three. 7-5 approximate pi

1. PTA Submission List

2. Design Ideas

There's nothing wrong with the basic framework of this code, but it's a little tricky because of the complexity of the calculations.

In the basic framework of the main function called the function Pi (EPS) to achieve the approximate PI/2 formula, and then store the value in pi, return the value of pi to the main function to multiply 2, the last output pi value.

The calculation of numerator and denominator is more complicated when the sub-function realizes approximate PI/2, so the calculation process is simple and clear.

3. Problems encountered in debugging process and PTA Submission List situation description.

(1) Error in logic analysis.

In a call to a child function, a item>x error in the Loop body statement.

The topic requires that the last item is less than the given accuracy of EPs, and the child function called when the X is EPs, so according to the requirements of the topic to change item>x to Item<x can be.

(2) Five digits after the decimal point are not retained.

Again because careless did not seriously examining, the topic explicitly requires to retain five decimal places, but I turn a blind eye, leading to the wrong answer.

I hope I will play code carefully again carefully!

4. Code.

Second, peer code peer evaluation

1. Mutual evaluation of students: Gao Jian Wei

2. My Code, mutual evaluation of the student code

Gao Xiawei The code of the classmate:

My Code:

3. What is the difference between my Gao Xiawei and my classmates ' code? What are their strengths? What style of code do you prefer?

The difference is that Gao Xiawei only called the function once, and I called the function two times.

Their advantages: Gao Xiawei's code is more concise and clear, she only called the function once. I called two functions, although in practice I can practice the call of function more, but in practical sense Gao Xiawei the code of the classmate is better.

I prefer the code of Gao Xiawei classmates.

Third, this week's topic set PTA Final ranking.

Iv. Summary of this week's study (2 points)

1. I learned how to use function calls to write programs, and also learned about the use of some recursive calls.

2. This week's content, you are not what?

For the teacher later added recursive call is really difficult to understand, there are some problems in PTA will not do.

Like 7-2,7-4,7-6,7-7,7-8,7-9,7-11 's problem.

3. Function Exam Summary

(1). Which problem is wrong, how to change it?

7-8 the question is the wrong answer.

I have tried many times or the answer is wrong, find the teacher to ask the classmate to do the problem as soon as possible.

(2). Are you satisfied with the exam results, how to improve?

More satisfied, try to be good.

Hope that they can be more careful, the probability of the wrong answer to careless high, no matter what to do must be careful.

I want to read more books and more dozen code.

PTA Experiment report (loop array function)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.