for循环习题(for循环习题).doc

  • 格式:doc
  • 大小:84.92 KB
  • 文档页数:9

for循环习题(for循环习题)

Please put these three the number of small to large output.

1. program analysis: we try to get the smallest number on X, the first

X compared with the Y, if the x>y will X and Y values of exchange, and

then x and Z are compared, if the x>z will X and Z values of exchange,

so that the minimum X.

[program 16]

Topic: the output of 9*9 formulas.

1. program analysis: branch and column considered, a total of 9 lines,

9 columns, I control line, J control column.

[program 17]

Question: monkeys eat peaches problem: monkeys picked off a few

peaches on the first day, immediately ate half, not addicted, and eat

a second day, the morning and the rest of the peach eaten half, and

eat one more. After every morning to eat the rest of the day before a

Yibanlingyi. By the tenth morning, when I wanted to eat again, I saw

only one peach left. Ask for the first day.

1. program analysis: reverse thinking, from the back to infer.

[program 18]

Title: two table tennis teams play, each with three players.

A team is a, B, C three, team B is x, y, Z three. The list of matches

has been drawn up. The team was asked for a list of the games. A says

he doesn't compare with X, and C says he doesn't compare with X, Z, and asks the program to find a list of the three team players.

1. program analysis: determine the prime number method: with a number

of removal of 2 to sqrt (this number), if you can be divisible, it

shows that this number is not prime, and vice versa is a prime number.

[program 19]

Title: print the following pattern (diamond)

*

* * *

Tiananmen

Result

Tiananmen

* * *

*

1. program analysis: first, the graphics are divided into two parts to

look at, the first four lines of a rule, the latter three lines of a

rule, the use of double for cycle, the first layer control line, the

second layer control column.

[program 20]

Title: there is a sequence of fractions: 2/1, 3/2, 5/3, 8/5, 13/8, 21/13... And the sum of the first 20 of the series.

1. program analysis: please seize the law of change of numerator and

denominator.

[program 21]

Title: 1+2, +3, ... +. . . +20. . . And...

1. program analysis: This program just accumulated into a tired ride.

[program 22]

Title: using recursive method for 5!.

1. program analysis: recursive formula: fn=fn_l*4!

[program 23]

Title: 5 people sit together and ask how old are fifth people? He said

he was 2 years older than fourth. Asked the age of fourth, he said he

was 2 years older than third. Asked third people and said they were

two years older than second. Asked second people, said two years older

than the first person. Finally asked the first man, he said, is 10

years old. How old are the fifth,please?

1. program analysis: the use of recursive method, recursive divided

into back push and recursive two stages. If you want to know the age

of fifth, you need to know the age of the first four, and so on, and

push to the first person (10 years old), and then push back.

[program 24]

Title: to a no more than 5 positive integers, requirements: first, ask

it is a few digits, two, the reverse print out your figures.

[program 25]

Title: a 5 digit number to determine whether it is palindrome. That is,

12321 is the palindrome number, the bit is the same as the tens, and

the ten bit is the same as the thousand.

[program 26]

Title: Please enter the first letter of the week to determine what day

it is. If the first letter is the same, then continue to judge the

second letters.

1. program analysis: it is better to use the case statement. If the

first letter is the same, then judge the second letters with the case

statement or the if statement.

Title: seek the prime number within 100 [program 28]

Title: sort 10 numbers 1. program analysis: can use the selection method, from 9 months after

the comparison process, select a minimum exchange with the first

element, the next analogy, with second elements and 8 Comparison and

exchange.

[program 29]

Title: the sum of the diagonal elements of a 3*3 matrix

1. program analysis: the use of double for loop control input two-dimensional array, and then a[i] [i] cumulative output.

[program 30]

Title: there is an array already in good order. Now enter a number,

the original law required to insert it into the array.

1. program analysis: first determine whether this number is greater

than the last number, and then consider the insertion of the number of

the middle, after inserting the element after the number, and then

move a position in turn.

Title: output an array in reverse order.

1. program analysis: use the first one and the last one.

[program 32]

Title: take an integer a, starting from the right side of the 4〜7 bit.