Loop-Function-array

Source: Internet
Author: User

Topic 1.7-7. Computing Strata and

1. PTA Submission List

2. Design Ideas

Enter n, use the loop to find the 1 to N class and sum it up

3. Problems encountered during commissioning

The subject only needs a loop.

4. Code

Topic 2.7-5 Find the minimum value

1. PTA Submission List

2. Design Ideas

Enter n number, assuming the first number is the minimum value, using the loop to compare the remaining number to the first, and if the result is smaller, replace the minimum value.

3. Problems encountered during debugging and PTA submission List situation description

The answer error with a minimum value of 0 is because two variables x and y are defined, and Y starts at 1 to meet the case where the minimum value is 0.

4. Code

Topic 3.7-17 Search 250

1. PTA Submission SITUATION

2. Design Ideas

Use the loop to enter n number, each input a number count plus one, until the number equals 250, jump out of the loop, output the count at this time.

3. Problems encountered during the submission process and PTA Submission List status note

4. Code

Two. Peer-to-peer evaluation of code pairs

1. Mutual evaluation of students ' names

Lin Ping

2. My code, classmate's code

3. Where do I differ from my classmates ' code? What are the advantages? What style of code do you prefer? If the classmate code is wrong, please help to point out where the problem.

(1). My Code does not set the middle value to calculate a change, the classmate's set up

(2) My relatively concise, the details of the students reflect more clearly, more can reflect the whole idea.

(3). I prefer my code.

Third, this week's topic set PTA Final Ranking

Iv. Summary of this week's study (2 points)
1. What have you learned?

Learned to use loops to enter, output, and determine, so that the code can be more concise.
2. This week's content, you are not what?

Multiple loops are not well mastered, making it easy to make the wrong answer.

3. Circular Structure Examination Summary

1. What is wrong with the question, and how to change it?

13. The output of the following program is

#include <stdio.h>

int main () {

int i=0,sum=0;

for (;;) {

if (i==3| | I==5) continue;

if (i==6) break;

i++;

Sum+=i;

}

When I=0 enters the loop, does not satisfy two if condition, I becomes 1,sum to 1, enters the loop again, does not satisfy two if condition, I changes to 2,sum to 3, enters the loop again, does not satisfy two if condition, I becomes 3,sum becomes 6, enters the loop again, satisfies the first if condition, Executes the continue statement, no longer executes the following statement, from this I constant equals 3, into the dead loop.

2. is the exam result satisfactory, how to improve?

Not very satisfied, examining to be serious, did the problem can not be wrong.

3. Other summaries.

To play more code, read more code, just look is not enough, hit the code is the most important is the accumulation of time.

Function

I. PTA LAB WORK

The title 1.7-8 the largest k primes within N and their

1. PTA Submission List

2. Design Ideas

Enter two numbers n and K, use the loop from N to subtract 1 to determine whether it is a prime number, when the sum of the total plus this prime, when the numbers of primes more than K, exit the loop.

3. Code

4. Problems encountered in commissioning process and PTA submission List status note

When x satisfies the condition, enter the continue statement, and when X reaches K, the break statement is used to exit the loop, otherwise the answer is incorrect.

Topic 2.7.1 Combinatorial number

1. PTA Submission List

2. Design Ideas

Enter m and N to calculate the class of M, the class of N, and the class of n-m, using the formula to find out the answer.

3. Code

4. problems encountered in commissioning process and PTA Submission List status Note

did not notice the format, missing the space.

Topic 3.7-4 Verification Goldbach conjecture

1. PTA Submission List

2. Design Ideas

Enter an n, using the determination of the loop and the prime number to find two primes less than n so that the sum of two is equal to N, and satisfies the minimum solution.

3. Code

4. problems encountered in commissioning process and PTA Submission List status Note

Two. The PTA final ranking as of this Sunday set.

Three. Peer-to-peer evaluation of code pairs

1. Mutual evaluation of the names of students

Zhu Chun-chun

2. My code, peer-to-peer code

3. Where do I differ from my classmates ' code? What are their advantages? What style of code do you prefer? If the classmate code is wrong, please help to point out where there is a problem

(1). The classmate's use of the function, I do not use

(2). After using the function of the students more concise and clear, my more simple to understand

(3). I like my classmates better, I use the function

Four. Summary of this week's study

1. What have you learned?

How to write code to judge prime numbers

2. This week's content, you don't have anything

For functions that are not very skilled to use

Array

First, PTA laboratory work

Topic 1: Finding the maximum value and subscript
1. PTA Submission List


2. Design Ideas
Use the array to define the number of N and take advantage of the loop input, assuming that the first number is the maximum value, again using the loop to compare the number behind it, if the result is larger, then replace the value of this maximum value and corresponding subscript.


3. Problems encountered in commissioning process and PTA submission List status note

The reason for the segment error is that when the array is defined, the [] cannot be an unknown number and should be used with a large enough amount.

4. Code

Topic 2:

1. PTA Submission List


2. Design Ideas

Using the array to define the number of N and the use of cyclic input, and then use the loop to the N number of subscript in reverse order, and then output the n number backwards.


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

A variety of errors occurred because the first method of using%d output results, ignoring the problem required by the end of the line can not have spaces. Therefore, you should use the IF statement condition to control the number of spaces.

4. Code

Topic 3.7-14 Simplified Insertion Sort

1. PTA Submission List

2. Design Ideas

Use the array to define the number of N and use the loop input, then enter an X, assign x to the number of n+1 in the array, and then use the sorting method to output it in order from small to large.


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

4. Code

Second, peer code peer evaluation

1. Mutual evaluation of students ' names

Lin Ping

2. My code, classmate's code

3. Where do I differ from my classmates ' code? What are the advantages? What style of code do you prefer? If the classmate code is wrong, please help to point out where the problem.

(1). My Code is determined by setting a flag=1 by the value of the flag, using the loop and if condition, if the upper half number is all 0, the value of flag is not changed, and if the value of flag is still unchanged after the end of the loop, the upper triangular matrix. The classmate's code is by setting two values representing the upper half of all numbers and the number of zeros, if equal is the upper triangular matrix.

(2). My code uses flag, a lot of code can borrow it to judge, the classmate code is more straightforward.

(3). I prefer my code, and later complex problems can be better solved

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

Iv. Summary of this week's study
1. What have you learned?

Learned to output multiple numbers with an array input

Learned to set a flag with a value of 0 or one to determine whether the condition is met.
2. This week's content, you are not what?

It's not good to use a two-dimensional array to simplify the code.

Loop-Function-array

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.