Kneel for Pascal's question bank

PASCAL basic problem program 1

Topic: Classic question: There is a pair of rabbits. From the third month after birth, they give birth to a pair of rabbits every month. After the third month, the little rabbit gives birth to a pair of rabbits every month. If rabbits don't die, what is the total number of rabbits per month?

Program 2

Topic: Judge how many prime numbers are between 10 1-200, and output all prime numbers.

1. program analysis: the method of judging the prime number: divide 2 by a number to sqrt (this number), if it can be divisible,

It means that this number is not prime, but prime.

Program 3

Title: Print out all "Narcissus". The so-called "daffodil number" refers to three digits, the sum of which is equal to the number itself. For example, 153 is a "daffodil number" because 153= 1 cubic +5 cubic +3 cubic.

1. Program analysis: Use for loop to control the number of 100-999, and each number is decomposed into units, tens and hundreds.

Procedure 4

Topic: decompose a positive integer into prime factors. For example, enter 90 and print 90=2*3*3*5.

Program analysis: to decompose the prime factor of n, we must first find a minimum prime number k, and then complete it according to the following steps:

(1) If this prime number is just equal to n, it means that the process of decomposing the prime factor is over, just print it out.

(2) If n

Repeat the first step.

(3) If n is not divisible by k, use k+ 1 as the value of k and repeat the first step.

Plan 5

Topic: use the nesting of conditional operators to complete this question: academic performance >; = Students with 90 points are represented by A, those with 60-89 points are represented by B, and those with less than 60 points are represented by C.

1. program analysis: (a>b)? This is a basic example of a conditional operator.

Program 6

Title: Enter two positive integers M and N, and find their greatest common divisor and least common multiple.

1. Program analysis: using rolling division.

Procedure 7

Title: Enter a line of characters and count the number of English letters, spaces, numbers and other characters.

Program 8

Topic: Find the value of s=a+aa+aaa+aaaa+aa ... A, where A is a number. For example, 2+22+222+2222+22222 (at this time * * * adds five numbers), and the addition of several numbers is controlled by the keyboard.

1. Program analysis: The key is to calculate the value of each item.

Program 9

Title: If a number is exactly equal to the sum of its factors, it is called "perfect number". Such as 6 = 1+2+3. The program finds all the perfect numbers in 1000.

Program 10

Title: A ball falls freely from the height of 100 meters, and bounces back to half the original height after each landing; Fall again and ask how many meters * * * passed when landing for the first time 10. How high is the rebound of 10?

Program 1 1

Title: There are 1, 2, 3, 4 numbers. How many different three digits can you make up? How much are they altogether?

Program 12

Title: Bonuses paid by enterprises are based on profits. When the profit (i) is less than or equal to 6,543,800 yuan, the bonus can be increased by 654.38+ 00%; When the profit is more than 6,543,800 yuan and less than 200,000 yuan, the part below 6,543,800 yuan will be deducted by 654.38+ 00%, and the part above 6,543,800 yuan will be deducted by 7.5%. Between 200,000 yuan and 400,000 yuan, 5% can be deducted for the part above 200,000 yuan; Between 400,000 and 600,000, the part above 400,000 can be deducted by 3%; Between 600,000 yuan and 6,543,800 yuan, the part above 600,000 yuan can get a commission of 654.38+0.5%; When it is higher than 6,543.8+0,000 yuan, the part above 6,543.8+0,000 yuan will receive a commission of 654.38+0%. Enter the profit I of the current month from the keyboard and find out the total bonus to be paid.

1. Program analysis: Please calibrate and locate with several axes. Note that the bonus should be defined as an increasing integer.

Program 13

Title: An integer, after adding 100, is a complete square number, and after adding 168, is a complete square number. What is the number?

1. Scheme analysis: If it is judged to be within 65438+ million, add 100 to this number before prescribing, and add 268 to this number before prescribing again. If the result after prescription meets the following conditions, it is a result. Please see the specific analysis:

Program 14

Title: Enter a day of a year to decide which day of the year it is.

1. Scheme analysis: Take March 5th as an example, first add up the first two months, and then add five days, which is the day of this year. Under special circumstances, consider adding one more day in leap year, and the input month is greater than 3.

Program 15

Title: Enter three integers X, Y, z Y, Z, please output these three numbers from small to large.

1. program analysis: we try to put the smallest number on x, and compare x and y first. If X >;; Y exchanges the values of X and Y, and then compares X and Z. If X >: Z exchanges the values of X and Z, X can be minimized.

Program 16

Title: Output 9*9 formula.

1. Program analysis: branch columns are considered, ***9 rows and 9 columns, I control row and J control column.

Program 17

Topic: Monkeys Eat Peaches: On the first day, the monkey picked a few peaches and ate half of them at once, which was not enough. He ate another one. The next morning, he ate half the remaining peaches and another one. After that, eat the remaining half of the day before every morning. 10 in the morning, when I wanted to eat again, I saw only one peach left. Ask how much you picked on your first day.

1. program analysis: adopt the method of reverse thinking and infer from back to front.

Program 18

Title: Two table tennis teams compete, each with three players. Team A consists of three people: A, B and C, while Team B consists of three people: X, Y, Z, Y and Z. The competition list has been decided by drawing lots. Someone asked the players about the list of matches. A says he won't compete with X, and C says he won't compete with X and Z. Please make a program to find out the names of the three teams. Plan 19

Read in temperature c, convert it into temperature f, and write a program. It is known that f=9/5*c+32 program 20 inputs A, B and C to find the root of the unary quadratic equation ax2+bx+c=0. Program 2 1 Enter the scores of 10 students in turn, and calculate the difference between each student's score and the average score, thus giving the letter grade of each student's score. A is higher than the average score of 10, B is within the average score of 10, and the rest is C. Finally, the number, grade and letter grade of each student are output, and each student occupies one line. Program 22 Slaughterhouse has the habit of killing pigs. Arranging n pigs to be slaughtered every day in a row in sequence, and slaughtering pigs in odd positions; Then put the remaining pigs in the last relative position, then kill the odd-numbered pigs after renumbering, and repeat the previous process until there is only one pig left, put the pigs back and kill them tomorrow. A clever pig found this rule and found a good position in advance so that he wouldn't be killed every day. When there are always n pigs, where should this clever pig stand? (n keyboard input) problem-solving guidance

Array is used to store the number of pigs, that is, a[i]=i is used in the initial loop statement, and then the pig killing process is simulated. Every time pigs are killed, all the pigs in odd positions are killed, and the pigs in even positions are renumbered, so that a[i]=a[i]*2 means that the pigs in even positions are renumbered. After a process of killing pigs, the number of pigs should be only n\2. Program 23. 1, 2, ..., n people sit in a circle clockwise. Start counting clockwise from 1 from the first person, stop counting when M reports, and those who sign up for M will get out of the queue, and so on clockwise from the next person until everyone gets out of the queue. Design a program to find out the queue order. Where n and m are input by the keyboard. When generating random numbers, the procedure 24 is usually repeated. Now we need to generate 20 random numbers in 100 and store them in the array. Finally, the array is output in the order from small to large, and the output is required to be on the same line, and each element is separated by a space. Procedure 25 A reconnaissance captain received an urgent task and asked him to select some people from six reconnaissance partners with code names A, B, C, D, E and F to scout a case. Because each scout has different specialties, candidates are required to pay attention to the following conditions in this case:

(1) At least one of Party A and Party B;

(2) A and D cannot go together;

(3) If D doesn't go, then E doesn't go either;

(4) Neither B nor C can go;

5] one of c and d;

[6] Two of the three people A, E and F should be sent.

Who should go? Program 26 allows the computer to generate a random integer within 1000, input a natural number from the keyboard, and if it is correct, input a guess prompt, otherwise prompt whether the input number is large or small. Finally, output the number of guesses. Program 27 inputs a positive integer a and factorizes it. For example:

Input: 20

Output: 20=2*2*5 Program 28 When measuring the mass of an object with a physical balance, the measured mass of the object is grams (A is an integer and less than 1 kg). Q: What weights should be in the weight plate of the balance at this time? Please select the minimum weight (the weight of the balance consists of the following weights: 500g 1, 200g 1, 100g 2, 50g 1, 20g 1, 10g 2, 5g 65440. Program 29 has n lights arranged in a row, numbered from 1 ~ n in turn. There are n people also numbered from 1 to n. No. 1 person (No.1) turns off all the lights, the second person (No.2) turns on all the lights that are multiples of 2, and the third person (No.3) turns on all the lights that are multiples of 3 (the lights are turned on; If they are closed, please open them). In the future, all people will do the same for No.3, enter n on the keyboard and output the numbers of the lights that are still on at last, with spaces between each number. Procedure 30 has a reasoning problem: the police officer found four suspects A, B, C and D at the scene where the deceased was killed. During the trial, A said "I didn't kill anyone", B said "C was the murderer", C said "The murderer must be D" and D said "C wronged a good man". Now we know that three of the four people are telling the truth, one is lying, and one and only one of the four suspects is the murderer. Please program to judge who is the real murderer. Program 3 1 Enter a decimal integer and enter the corresponding binary number. Procedure 32 In a certain sports meeting, the scores of 100M of 8 athletes (unit: seconds) are as follows:

Number of athletes ($ Number) 100 meter performance

860 12.7

576 1 1.3

30 1 13.5

455 12.6

102 12.0

377 1 1.0

023 12.5

530 13.2

It is required to sort by 100M, showing the number and achievements of the top three athletes. Problem-solving guidance

It is preferable to use the recording type storage program 33 to fill in two following equations with the same number, so that the equation can be established.

□3*6528=3□*8256

Finally, the whole complete equation needs to be output. Program 34 The cube of any positive integer can be written as the sum of a group of adjacent odd numbers.

For example: 33 = 7+9+11= 2743 =13+15+17+19 = 64.

This is the Nicochis theorem. Please write a program to verify this theorem and output any integer. Please refer to the following examples of output formats:

Input: 4

Output: 4 (3) =13+15+17+19 = 64 Program 35 Four foreign students A, B, C and D from different countries are talking together. They can only speak two of the four languages. The situation is that A can speak Japanese and D can't. A and D can talk to each other, and B can't speak English, but when A and C talk, B needs to be an interpreter. B, C and D want to communicate with each other, but they can't speak the same language, and only three people can speak one language. Please program to determine which two languages the four foreign students A, B, C and D can speak. Program 36 A car is driving at a fixed speed. In the morning, the driver sees that the reading on the odometer from left to right is the same as that from right to left, which is 95859. Seven hours later, a new symmetrical number appeared on the odometer. What is the speed of this car (in whole numbers)? What is this new symmetric number? Set the odometer to 5 digits. Program 37 Xiaohong is 0/2 years old this year, and her father is 20 years older than her. Write a program to calculate that her father will be twice her age in a few years. How old were they then? Article 38 The methods for determining the first-class scholarships of schools are as follows:

(1) The total score of the five courses tested exceeds 450 points;

(2) The scores of all courses are above 88;

(3) The scores of the first three courses (main courses) are above 95, and the scores of the other two courses (non-main courses) are above 80.

Anyone who meets any of the above conditions can be recognized as a first-class scholarship. Enter a student's grades in five courses to decide whether he can get the first-class scholarship. The program 39 at the top and bottom of the window calculates and outputs the value of. pi. using the following formula:

π/4 =1-1/3+1/5-1/7+...+1/(4n-3)-1(4n-/kloc) kloc-0//3- 1/4…+ 1/99- 1/ 100。

There is no discount for shopping below 250 yuan;

Shopping in 250 yuan (including 250, the same below) is dissatisfied with 500 yuan, and the price is reduced by 5%;

Shopping in 500 yuan is insufficient 1000 yuan, and the price is reduced10%;

When shopping is over 1000 yuan but less than 2,000 yuan, it will be reduced15%;

20% discount on purchases over 2000 yuan.

Enter the payment for goods and calculate the actual amount payable by the customer. Program 43 uses screening method to find prime numbers. Within 255, the program 44 uses the high-precision addition and subtraction program 45 to find the power function m n recursively, and the exponentiation program 46 that inputs m and n prints out12 3 4 5 6.

1 2 3 4 5 6

1 2 3 4 5 6

1 2 3 4 5 6

1 2 3 4 5 6

1 2 3 4 5 6

1 2 3 4 5 6 The following is the output n of a program 47 of Huishuo method, and its arrangement number is input: 3 output:1231312321program 48 output n, m, (n The starting point is (1, 1) and the ending point is (n, n). Find the shortest path. Input: 4010000 0110000 0. 2) (4,2) (4,3) (4,4) 6 Program 5 1 A traveler has a backpack that can use up to m kilograms, and now he has n items. Their weights are W 1, W2, ..., Wn, and their values are C 1, C2, ... input: 5 10 2 33 24 5655 output: 1 1 The following is the search and sorting program 52, fast.