Loop array functions

Source: Internet
Author: User

Array

1.

To find the maximum value and its subscript

Design ideas:

First enter a set of numbers (that is, use an array), define a temp=a[0], and cycle by comparison, until the end.

Attention should be paid to the problem of minimum subscript.

The flowchart is as follows:

Error:

It's too long, I forgot.

It seems that the output is not the smallest subscript.

That's right:

2 Find integer

Design ideas:

First enter a string of integers (that is, using an array), the cycle of comparison, if there is flag=1;

If not, then flag=1.

The flowchart is as follows:

Error:

This problem is submitted without errors, because the problem can be run on its own check out right, so there is no wrong commit.

When you write, you forget to use loops when comparing.

That's right:

3. Square loop right shift

Design ideas:

Similar to normal array loop right shift

Flow chart:

Cause of Error:

This inscription is difficult because it is a two-dollar array, so it is looped around the halo

Then input too much trouble, no test on the submitted.

That's right:

Total rankings:

Students ' Mutual Evaluation:

I always liked the code of my classmates. The choice sort of the question I've been partly right

Jian Wei classmate is very good, I want to learn from you.

Summarize:

1. What have you learned?

① I learned to store numbers and strings in arrays.

② input and output strings can be used with%s, and can be used with gets and puts. When storing a string with%s, if you enter a space, the system directly considers the string to end. The get will pay the entire string to know the line break. %c is output letters one after the other.

③ learned to use strlen (to calculate the length of a string), strcat (concatenate two strings), strcmp (comparing the length of a string), strcpy (pasting one string into another) to handle the string.

④ using two-dimensional arrays to solve matrix-related problems

⑤ uses the selection sort method and the bubble sort method to arrange the numbers in an array in a certain order.

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

PTA: 5,7 8,9,15,16,23

Many can not be used skillfully, especially now forget a lot.

Function

    1. Number of combinations:

Design ideas:

Direct numerator denominator is convenient to call the same function

The child function uses the loop to find the factorial.

Error:

Cause of Error:

Multiplication hand is written in addition;

That's right:

2. Judging prime numbers  

Design ideas:

First of all, we need to define the prime number, and then according to the problem of recycling

Design sub-functions, also more convenient

Error:

Cause of Error:

I don't know, I think it's all wrong.

That's right:

3. Sort by bubbling

Design ideas: Not sure, see the flowchart for details:

Students ' Mutual Evaluation:

High school code is clear, although simple, but very intuitive

is very rigorous, but it seems that the function of the master is not very handy,

This question is simple, but I have no reference to the topic of the function, I hope the high school students and I progress together.

Last ranking

Summarize

The function of the very heart tired, during the feeling experienced a lot of difficulties. From the beginning of the definition is not,

I'm happy that I've been able to call the function a little bit now to find a simpler way, but the PTA function

It's so hard, I can't write, I'm very distressed by the call to define parameters.

I also know the importance of learning functions, function calls always make the problem more intuitive, clearer thinking, learn the function is very important!

Cycle

1   Polynomial summation

Design ideas:

First enter an integer n,

Loop input n times,

Defines a flag that requires the definition of flag=-1 when adding, and flag=1 when subtraction;

Define sum=0;

implementation of sum=x+flag*1.00/j;

2 ask for 1 to 100 of the and

Design ideas:

Define I with a loop.

Error

Cause no space is played

3. sum of power

Design ideas:

This problem is very simple, call the POW function, loop accumulation can

Students ' Mutual Evaluation:

Jian Wei classmate's code is very clear, easier to read, but I think, I used the function, so, uh. It's not the same. Learn to make progress together

Summarize:

After the cycle of this group of exercises, I learned that the format is very important, especially in the PTA,

When you meet a complex multi-loop, you can choose to invoke the function so that it is beautiful and clearer.

In short, need to clarify the idea, draw a good flowchart is very important, step by step follow the idea of code.

Loop array functions

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.