50 programming questions, save your own practice

Source: Internet
Author: User
Tags case statement greatest common divisor

"Program 1"
Title: Classical Questions: There are a pair of rabbits, from the 3rd month after birth a pair of rabbits each month, the rabbit long to the third month after the birth of a month
For rabbits, if the rabbits are not dead, ask the total number of rabbits per month?
1. Program Analysis: The law of Rabbits for the series 1,1,2,3,5,8,13,21 ....

"Program 2"
Title: Determine the number of primes between 101-200 and the output of all primes.
1. Procedure analysis: The method of judging primes: to remove 2 to sqrt (this number) by a number, if it can be divided evenly,
It indicates that the number is not a prime and vice versa.

"Program 3"
Title: Print out all the "daffodils", the so-called "Narcissus number" refers to a three-digit number, its number of cubes and equal to the number itself. For example:
153 is a "narcissus number", because the 153=1 three times the square +5 of the three +3 Times Square.

"Program 4"
Title: Decompose a positive integer into factorization. For example: Enter 90 and print out 90=2*3*3*5.
Program Analysis: The decomposition of n factorization, should first find a minimum prime number k, and then the following steps to complete:
(1) If the prime number is exactly equal to N, then the process of decomposing the factorization is finished and printed out.
(2) if n<>k, but n can be divisible by K, the value of k should be printed, and n divided by the quotient of K, as a new positive integer you n, repeat the first step.
(3) If n cannot be divisible by K, the first step is repeated with k+1 as the value of K.

"Program 5"
Title: Use the nesting of conditional operators to complete this problem: Students with a >=90 score of a, 60-89 points between the B, 60 points below
is expressed in C.
1. Program Analysis: (a>b)? A:b This is a basic example of a conditional operator.

"Program 6"
Title: Enter two positive integers m and N to find their greatest common divisor and least common multiple.
1. Program Analysis: The use of rolling division.

"Program 7"
Title: Enter a line of characters, respectively, the number of English letters, spaces, numbers and other characters.
1. Program Analysis: Using the while statement, the condition for the input character is not ' \ n '.

"Program 8"
Title: The value of S=A+AA+AAA+AAAA+AA...A, where a is a number. For example, 2+22+222+2222+22222 (a total of 5 numbers are added at this time),
Several numbers are added with keyboard control.
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, this number is called the "end number". For example, 6=1+2+3. Programming to find all the ends within 1000

"Program 10"
Title: A ball from the height of 100 meters of freedom falling, each landing back to the original height of half, and then fall, to beg it on the 10th landing, the total through too much
Less rice? How high is the 10th time rebound?

"Program 11"
Title: There are 1, 2, 3, 4 numbers, can make up how many different and no repetition of the number of three digits? How much are they?
1. Program Analysis: Can be filled in the hundred, 10 digits, digit digits are 1, 2, 3, 4. Make all the permutations and then remove the permutations that do not meet the criteria.

"Program 12"
Title: The bonuses awarded by the Enterprise are based on the profit commission. Profit (I) less than or equal to $100,000, bonus can be raised 10%, profit is higher than 100,000 yuan, less than 200,000
Yuan, less than 100,000 yuan part by 10% commission, higher than 100,000 yuan portion, Cocoa Commission 7.5%, 200,000 to 400,000, higher than 200,000 yuan of the department
5%, 400,000 to 600,000 is higher than 400,000 yuan, can be a commission of 3%, 600,000 to 1 million, higher than 600,000 yuan of the portion, can be
Commission 1.5%, higher than 1 million yuan, more than 1 million yuan of the portion of 1% commission, from the keyboard input of the month profit I, the total bonus should be issued?
1. Program Analysis: Please use the axis to demarcation, positioning. Note that the bonus definition should be defined as the growth integral type.

"Program 13"
Title: An integer, which plus 100 is a complete square number, plus 168 is a complete square number, what is the number?
1. Procedure analysis: Within 100,000 to judge, the number plus 100 after the root, and then the number plus 268 after the root, if the result of the root to meet
The following conditions, that is, the result. Please see the specific analysis:

"Program 14"
Title: Enter a certain day of the year, judging the day is the first of the year?
1. Procedure analysis: Take March 5 as an example, should first add up the first two months, and then add 5 days that is the first day of the year, special cases, leap years and
Enter the month greater than 3 o'clock to consider more than one day.

"Program 15"
Title: Enter three integers x, y, Z, please put these three numbers from small to large output.
1. Procedure analysis: We find a way to put the smallest number on X, first compare x with Y, if x>y the value of x and Y, and then X
Compared to Z, if x>z the value of X and Z, this will make x the smallest.

"Program 16"
Title: Output 9*9 formula.
1. Program Analysis: Branch and column considerations, a total of 9 rows 9 columns, I control row, J control column.

"Program 17"
Title: Monkey Eat Peach problem: The first day of monkeys to take off a number of peaches, immediately ate half, not addicted, and eat a second morning again will remain
The peach below ate half and ate one more. And then every morning, the day before, the rest.
Half of the zero one. When I want to eat again in the morning of the 10th day, I see only one peach left. For the first day to pick a total number.
1. Procedure analysis: Adopt the method of reverse thinking, infer from the backward forward.

"Program 18"
Title: Two table tennis team to play, each out three people. Team A for A,b,c three, team B for X, Y, z three people. Have drawn lots to determine the contest list. Someone to
The players inquired about the list of matches. A says he does not compare with X, C says he does not compare with x,z, please compile the procedure to find out the list of the three teams.
1. Program Analysis: The method of judging the prime number: The number is removed from 2 to sqrt (this number), if it can be divisible, it indicates that the numbers are not prime, anti-
is the prime number.

"Program 19"
Title: Print out the case (diamond)
1. Program Analysis: First the graphics into two parts to see, the first four lines a rule, after three lines a rule, the use of double for loop, the first layer of control
Row, second level control column.

"Program 20"
Title: There is a fractional sequence: 2/1,3/2,5/3,8/5,13/8,21/13 ... to find out the sum of the first 20 items of this series.
1. Procedure analysis: Please grasp the molecular and the denominator of the law of change.

"Program 21"
Title: Seeking the 1+2!+3!+...+20! and
1. Program Analysis: This program just adds the accumulation into the multiplicative.

"Program 22"
Title: Using recursive method to find 5!.
1. Program Analysis: Recursive formula: fn=fn_1*4!

"Program 23"
Title: 5 people sit together and ask how old is the five? He said he was 2 years older than the 4th one. Asked the age of 4th, he said he was 2 years older than the 3rd man. Ask
The third person, also said two years old than the 2nd People's Congress. Ask the 2nd person, who says two years older than the first one. Finally asked the first person, he said is 10 years old. May I ask the fifth one
How old are you?
1. Procedure analysis: Recursion is divided into two stages, recursive and recursive, using recursive method. To know the age of a fifth person, you need to know the age of the fourth person,
And so on, push to the first person (10 years old), and then push back.

"Program 24"
Title: Give a positive integer not more than 5 digits, requirements: First, it is a number of digits, second, the reverse print out the figures.

"Program 25"
Title: a 5-digit number, judging whether it is a palindrome number. That is, 12321 is a palindrome number, single-digit and million-bit the same, 10 bits and thousands of the same.

"Program 26"
Title: Please enter the first letter of the day of the week to determine the day of the week, if the first letter, then continue to judge the second letter.
1. Procedure analysis: Use the situation statement is better, if the first letter, then judge the case statement or if statement to determine the second letter.

"Program 27"
Title: Number of primes within 100

"Program 28"
Title: Sort 10 Numbers
1. Program Analysis: You can use the selection method, that is, from the next 9 comparison process, select a minimum and the first element exchange,
Two elements are compared with the latter 8 and exchanged.

"Program 29"
Title: Finding the sum of diagonal elements of a 3*3 matrix
1. Program Analysis: Use the dual for loop control input two-dimensional array, and then add a[i][i] after the output.

"Program 30"
Title: There is an array that has been sequenced. Now enter a number that requires it to be inserted into the array as it was originally.
1. Program Analysis: First determine whether this number is greater than the last number, and then consider inserting the middle number of cases, after inserting this element after the number,
Move back one position in turn.

Finish "program 31"
Title: Output an array in reverse order.
1. Procedure analysis: With the first and the last exchange.

"Program 32"
Title: Take an integer A from the right end of the 4~7 bit.
Program Analysis: This can be considered:
(1) First move A to the right 4 bits.
(2) set a low 4 bit is all 1, the rest is all 0 of the number. Available ~ (~0<<4)
(3) Perform & operations on the above.

"Program 33"
Title: Print out the Yang Hui triangle (requires 10 lines to print)
1. Program Analysis:
1 1
1 2 1
1 3 3 1
1 4 6) 4 1
1 5 10 10 5 1

"Program 34"
Title: Enter 3 number a,b,c, output by size order.
1. Procedure analysis: Using the pointer method.

"Program 35"
Title: The input array, the largest exchange with the first element, the smallest with the last element interchange, the output array. "Program 36"
Title: There are n integers, so that they move backward in the order of the first number of M positions, the last m number becomes the first number of M

"Program 37"
Title: There are n people around in a circle, order automatic arranging. Starting from the first person (from 1 to 3 off), where 3 of the people quit the circle, ask the last to stay
Is the number of the original number of the person.

"Program 38"
Title: Write a function to find the length of a string, enter a string in the main function, and output its length.

"Program 39"
Title: Write a function, input n is even, call function to 1/2+1/4+...+1/n, when input n is odd, call function
1/1+1/3+...+1/n (using pointer functions)

"Program 40"
Title: String sorting.

"Program 41"
Title: There are a bunch of peaches on the beach, five monkeys to divide. The first monkey divided this pile of peaches into five copies, one more, and this monkey put more of a
Threw it into the sea and took a copy of it. The second monkey divided the remaining peaches evenly into five, and one more, and it threw many more into the sea.
, took a copy, the third, the fifth and the other monkeys are doing this, asked the beach at least how many peaches?

"Program 42"
Title: 809*?? =800*?? +9*?? +1
Where?? The two-digit number represented, 8*?? The result is a two-digit number, 9*?? The result is a 3-digit number. Please?? The two-digit number represented, and 809*?? After the result.

"Program 43"
Title: An odd number of 0-7 can be composed.

"Program 44"
Title: An even number is always expressed as the sum of two primes.

"Program 45"
Title: Judging a prime number can be divisible by several 9

"Program 46"
Title: Two string connection programs
Finish "program 47"
Title: Reads an integer value of 7 numbers (1-50), each reading a value, the program prints out the number of *.

"Program 48"
Title: A company uses a public telephone to pass data, the data is a four-bit integer, is encrypted during delivery, encryption rules are as follows: each digit
Add 5, then replace the number with the remainder of 10, and then swap the first and fourth bits, second and third.

Finish "program 49"
Title: Count the number of occurrences of a string's substrings

"Program 50"
Title: There are five students, each student has 3 courses of results, from the keyboard input above data (including student number, name, three lessons), calculate the average score, the original data and calculated average scores are stored in the disk File "stud".

50 programming questions, save your own practice

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.