Typical C language 100 questions (1-40)

Source: Internet
Author: User

This typical C language 100 question is found online. This is also available in programming enthusiast forums.

Note: I may have skipped some questions, but I have not done anything about the graphics. There are still a few questions that are not a question at all, so they are not done either.

Some questions appear twice because two different answers are written.

[Procedure 1] Question: How many three numbers can be composed of 1, 2, 3, and 4 distinct and non-repeated numbers? What is it? 1. Program Analysis: It can be filled in hundreds of digits, ten digits, and one digit is 1, 2, 3, and 4. Make up all the sorting before dropping the sorting that does not meet the conditions. 2. program source code: # include <stdio. h> # include <stdlib. h> int main () {int I, j, k; for (I = 1; I <5; I ++) for (j = 1; j <5; j ++) for (k = 1; k <5; k ++) if (I! = J & I! = K & J! = K) printf ("% d", I, j, k); System ("pause"); Return 0;} [Program 2] Question: the enterprise's bonus is based on the profit. If the profit (I) is less than or equal to 0.1 million yuan, the bonus can be raised by 10%; if the profit is higher than 0.1 million yuan, if the profit is lower than 0.2 million yuan, the portion lower than 0.1 million yuan will be charged by 10%, and the portion higher than 0.1 million yuan, 7.5% for Coco; 0.2 million for 0.4 million to 0.2 million yuan; 5% for 0.4 million to 0.6 million yuan; 0.4 million for 3% to Yuan; between 0.6 million and 1 million, if the price is higher than 0.6 million yuan, the price can be increased to 1.5%. If the price is higher than 1 million yuan, the price of more than 1 million yuan is increased by 1%, and the current month's profit is input from the keyboard, how many bonuses should be paid? 1. Program Analysis: Use the number axis to divide and locate. Note that you need to define the bonus type as a growth integer. 2. program source code: # include <stdio. h> # include <stdlib. h> int main () {long profit; double rate1 = 0.1, rate2 = 0.075, rate3 = 0.05, rate4 = 0.03, rate5 = 0.015, rate6 = 0.01; long reward = 0; printf ("input monthly profit:"); scanf ("% d", & profit); If (profit> = 0 & profit <= 100000) Reward = profit * rate1; else if (profit <= 200000) Reward = 100000 * rate1 + (profit-100000) * rate2; else if (profit <= 400000) reward = 100000 * rate1 + 100000 * rate2 + (profit-200000) * rate3; else If (profit <= 600000) Reward = 10000 * rate1 + 100000 * rate2 + 200000 * rate3 + (profit-400000) * rate4; else if (profit <= 1000000) reward = 10000 * rate1 + 100000 * rate2 + 200000 * rate3 + 200000 * rate4 + (profit-6000000) * rate5; else reward = 10000 * rate1 + 100000 * rate2 + 200000 * rate3 + 200000 * rate4 + 400000 * rate5 + (profit-1000000) * rate6; printf ("% d \ n ", reward); System ("pause"); Return 0;}/* [Program 3] Question: an integer. After adding 100, it is a complete number of workers, in addition, 168 is a full shard number. What is this number? */# Include <stdio. h> # include <stdlib. h> int main () {int I, X, Y; Double R; for (I = 0; I <100000; I ++) {x = (INT) SQRT (I + 100); y = (INT) SQRT (I + 268); If (x * x = (I + 100) & Y * Y = I + 268) {printf ("% d \ n", I); break ;}} system ("pause"); Return 0 ;} /* [Procedure 4] Question: Enter the day of a month to determine the day of the year? "The year that can be divisible by four but cannot be divisible by 100 or 400 is a leap year" */# include <stdio. h> # include <stdlib. h> typedef struct {int year; int month; int day;} date; int main () {int months [12] = {31,28, 31,30, 31,30, 31,31, 30,31, 30,31}; int days = 0, I; date; scanf ("% d", & (date. year), & (date. month), & (date. day); // enter a date such as 2012 3 10 for (I = 0; I <date. month-1; I ++) days + = months [I]; days + = date. day; If (date. year % 4 = 0 & date. year % 100! = 0) | (date. year % 400 = 0) days + = 1; printf ("This day is the % d day of the year \ n", days); System ("pause "); return 0;}/* [Program 5] Question: Enter three integers x, y, and z. Please output these three numbers from small to large. */# Include <stdio. h> # include <stdlib. h> int main () {int x, y, z; scanf ("% d", & X, & Y, & Z ); printf ("% d", (x <Y? X: Y) <Z? (X <Y? X: Y): Z, (x> Y? X: Y) <Z? (X> Y? X: Y): Z, (x> Y? X: Y)> Z? (X> Y? X: Y): Z); X = Y <Z? Y: Z; System ("pause"); Return 0;}/* [Program 6] Question: Use * to output the C pattern. */# Include <stdio. h> # include <stdlib. h> int main () {printf ("** \ n"); printf ("* \ n"); printf ("* \ n "); printf ("* \ n"); printf ("** \ n "); system ("pause"); Return 0;}/* [Program 7] Question: Output A special pattern. Run it in the C environment. Have a look, very beautiful! */# Include <stdio. h> # include <stdlib. h> int main () {int I; for (I = 0; I <128; I ++) printf ("% C", I ); system ("pause"); Return 0;}/* [Program 8] Question: Output 9*9 tips. */# Include <stdio. h> # include <stdlib. h> int main () {int I, j; For (j = 1; j <10; j ++) {for (I = 1; I <= J; I ++) {printf ("% DX % d = %-3D", I, j, I * j);} printf ("\ n ");} system ("pause"); Return 0;}/* [Program 9] Question: Required to output the chess board. 1. Program Analysis: Use I control rows and J to control columns, and control the output black square or white square according to the sum of I + J. */# Include <stdio. h> # include <stdlib. h> int main () {int I, j; for (I = 0; I <8; I ++) {for (j = 0; j <8; j ++) if (J + I) % 2 = 0) printf ("% C", 219); else printf (""); printf ("\ n") ;}system ("pause"); Return 0 ;}/ * [program 10] Question: print the stairs and print two smiling faces above the stairs. */# Include <stdio. h> # include <stdlib. h> int main () {int I, j, k; printf ("% C \ n", 2, 2); for (I = 1; I <10; I ++) {for (j = 1; j <I; j ++) printf ("% C", 219,219); printf ("\ n ");} system ("pause"); Return 0;}/* [Program 11] Question: classical problem: there is a rabbit. every month from the first 3rd months after birth, a rabbit is born, after the third month, the bunny gave birth to another rabbit every month. If the Rabbit does not die, how many rabbits are there every month? */# Include <stdio. h> # include <stdlib. h> long getnum (int n); int main () {int N; scanf ("% d", & N ); printf ("% d months % d rabbits \ n", N, getnum (n); System ("pause"); Return 0 ;} long getnum (int n) {If (n = 1 | n = 2) return 1; else return (getnum (n-1) + getnum (n-2 ));} /* [program 12] Question: Judge the number of prime numbers between and, and output all prime numbers. */# Include <stdio. h> # include <stdlib. h> int isprimer (int n); int main () {int I; for (I = 101; I <201; I ++) if (isprimer (I )) printf ("% d", I); System ("pause"); Return 0;} int isprimer (int n) {int I; int S = SQRT (N) + 1; for (I = 2; I <s; I ++) if (N % I = 0) return 0; return 1 ;} /* [Program 13]: print out the "Daffodils" of-. The so-called "Daffodils" refers to a three-digit number, each of which is equal to the number itself. For example, 153 is a "Daffodils" because 153 = the power of 1 + the power of 5 + the power of 3. */# Include <stdio. h> # include <stdlib. h> int main () {int I, j, k; for (I = 1; I <10; I ++) for (j = 0; j <10; j ++) for (k = 0; k <10; k ++) if (I * I * I + J * j + K * k x K = I * 100 + J * 10 + k) printf ("% d", I, j, k); System ("pause"); Return 0 ;}/ * [Program 14] Question: factorization a positive integer into a prime factor. For example, enter 90 and print 90 = 2*3*3*5. */# Include <stdio. h> # include <stdlib. h> int isprimer (int n); int explode (int n); int main () {int N; scanf ("% d", & N ); printf ("% d =", n); While (! Isprimer (N) {n = explode (n);} printf ("% d", n); System ("pause"); Return 0 ;} int isprimer (int n) {int I; int S = SQRT (n) + 1; for (I = 2; I <s; I ++) if (N % I = 0) return 0; return 1 ;}int explode (int n) {int I; for (I = 2; I ++) if (N % I = 0) {printf ("% d *", I); return N/I ;}/ * [program 15] Question: use the nested conditional operators to complete this question: Students with scores greater than or equal to 90 are represented by a, students with scores between 60 and 89 are represented by B, and students with scores below 60 are represented by C. */# Include <stdio. h> # include <stdlib. h> int main () {int grade; char rank; scanf ("% d", & grade); Rank = Grade> = 90? 'A' :( grade> = 60? 'B': 'C'); printf ("% C \ n", rank); System ("pause"); Return 0 ;}/ * [Program 16] Question: enter two positive integers, M and N, and calculate the maximum common divisor and the minimum common multiple. Initial code: */# include <stdio. h> # include <stdlib. h> int gcd (int m, int N); int lcm (int m, int N); int main () {int M, N; scanf ("% d", & M, & N); printf ("maximum common divisor: % d, minimum common multiple: % d \ n", gcd (m, n), lcm (m, n); System ("pause"); Return 0;} int gcd (int m, int N) {int big, small; int I; big = m> n? M: N; small = m <n? M: N; for (I = small; I> 0; I --) if (big % I = 0 & Small % I = 0) {return I ;}} int lcm (int m, int N) {int big = m> n? M: N; int small = m <n? M: N; int I; for (I = big; I ++) if (I % big = 0 & I % small = 0) return I ;} // Upgrade Code:/* [Program 16] Question: enter two positive integers m and n to obtain the maximum public approx. And the minimum public multiples. */# Include <stdio. h> # include <stdlib. h> int main () {int m, n, TEM; int big, small; scanf ("% d", & M, & N ); big = m> n? M: N; small = m <n? M: N; while (big % small )! = 0) {TEM = big % small; big = TEM> small? TEM: small; small = TEM <small? TEM: small;} printf ("maximum common divisor: % d \ n", small); printf ("minimum common multiple: % d \ n", (M * n) /small); System ("pause"); Return 0;}/* [Program 17] Question: enter a line of characters, the numbers of English letters, spaces, numbers, and other characters are counted respectively. */# Include <stdio. h> # include <stdlib. h> # include <string. h> int main () {char C; int I; int num1 = 0, num2 = 0, num3 = 0, num4 = 0; while (C = getchar ())! = '\ N') {If (C> = 'A' & C <= 'Z ') | (C> = 'A' & C <= 'Z') num1 ++; else if (C> = '0' & C <= '9') num3 ++; else if (C = '') num2 ++; else num4 ++;} printf ("English letter count: % d, number of spaces: % d, number of characters: % d, other characters: % d \ n ", num1, num2, num3, num4); System ("pause"); Return 0;}/* [Program 18] Question: calculate S = a + AA + AAA + AAAA + AA... the value of A, where A is a number. For example, 2 + 22 + 222 + 2222 + 22222 (a total of 5 numbers are added at this time), and the addition of several numbers is controlled by the keyboard. (INT) Pow (10, Count-I); */# include <stdio. h> # include <stdlib. h> int main () {int A, Count, r = 0, I, j, TEM; scanf ("% d", & A, & COUNT ); for (I = count; I> 0; I --) {TEM = A * I; for (j = 0; j <count-I; j ++) TEM * = 10; R + = TEM;} printf ("% d \ n", R); System ("pause"); Return 0 ;} /* [Program 18] Question: S = a + AA + AAA + AAAA + AA... the value of A, where A is a number. For example, 2 + 22 + 222 + 2222 + 22222 (a total of 5 numbers are added at this time), and the addition of several numbers is controlled by the keyboard. (INT) Pow (10, Count-I); */# include <stdio. h> # include <stdlib. h> int main () {int A, N, Count = 0, Sn = 0, Tn = 0; scanf ("% d", & A, & N ); while (count <n) {tn + = A; Sn + = tn; A * = 10; count ++;} printf ("% d \ n", SN ); system ("pause"); Return 0;}/* [Program 19] Question: If a number is equal to the sum of its factors, it is called the "End number ". For example, 6 = 1 + 2 + 3. Program to find all the completion numbers within 1000. */# Include <stdio. h> # include <stdlib. h> # include <math. h> int main () {int I, j, TEM, N; for (I = 2; I <= 1000; I ++) {TEM = 0; for (j = 1; j <I; j ++) if (I % J = 0) {TEM + = J;} If (TEM = I) printf ("% d", I);} system ("pause"); Return 0;}/* [Program 20] Question: A ball falls freely from the height of 100 meters, after each landing, the system jumps back to half of the original height, and then falls down. How many meters does it go through during the first landing? How high is the rebound of 10th times? */# Include <stdio. h> # include <stdlib. h> int main () {float SH = 100.0, H = 50.0; int I; for (I = 2; I <= 10; I ++) {sh + = 2 * h; H/= 2;} printf ("% F \ n", sh, H); System ("pause "); return 0;}/* [Program 21] Question: Monkey peach eating problem: the monkey picked a few peaches on the first day, and it was half eaten immediately, not enough, I eat another one, and then I eat half of the peaches the next morning. In the future, I eat the remaining half of the previous day every morning. When you want to eat again in the morning of the seventh day, there is only one peach left. Calculate the total number of extracted items on the first day. */# Include <stdio. h> # include <stdlib. h> int main () {int I, S = 1; for (I = 9; I> 0; I --) {S = (S + 1) * 2 ;} printf ("% d peaches \ n", S); System ("pause"); Return 0 ;}/ * [Program 22] Question: two table tennis teams competed, with three members each. Team A is A, B, and C, and Team B is X, Y, and Z. The game list has been determined by lottery. Someone asked the players about the game list. A said that he is not in comparison with X, C said that he is not in comparison with X and Z. please compile a program to find a list of three-team players. */# Include <stdio. h> # include <stdlib. h> int main () {char I, j, k = 'y'; for (I = 'y'; I <= 'Z'; I ++) {for (j = 'X'; j <= 'Z'; j ++) {if (I! = J & I! = K & J! = K & I! = 'X' & K! = 'X' & K! = 'Z') printf ("the order is a -- % C, B -- % C, C -- % C \ n", I, j, k );}} system ("pause"); Return 0;}/* [Program 23] Question: print the case (diamond) * ****************************/# include <stdio. h> # include <stdlib. h> int main () {int I, j; for (I = 1; I <= 4; I ++) {for (j = 0; j <I; j ++) {printf ("*") ;}printf ("\ n") ;}for (I = 3; I> 0; I --) {for (j = I; j> 0; j --) printf ("*"); printf ("\ n") ;}system ("pause "); return 0;}/* [Program 24] Question: a fractional sequence: 2/1, 3/2, 5/3, 8/5, 13/8, 21/13... Calculate the sum of the first 20 items of the series. */# Include <stdio. h> # include <stdlib. h> int main () {int I, TEM; double S = 0, A = 2, B = 1; for (I = 0; I <20; I ++) {S + = A/B; TEM = B; B = A; A = a + TEM;} printf ("% lf \ n", S ); system ("pause"); Return 0;}/* [Program 25] Question: 1 + 2! + 3! +... + 20! And */# include <stdio. h> # include <stdlib. h> int main () {int A = 1, s = 0, I; for (I = 1; I <= 20; I ++) {A * = I; S + = A;} printf ("1 + 2! + 3! +... + 20! = % D \ n ", S); System (" pause "); Return 0;}/* [Program 26] Question: Use recursive method to calculate 5 !. */# Include <stdio. h> # include <stdlib. h> int getnum (int n); int main () {int N; printf ("5! = % D \ n ", getnum (5); System (" pause "); Return 0;} int getnum (int n) {If (n = 1) return 1; else if (n> 1) Return (N * getnum (n-1); else return 0;}/* [Program 27] Question: Using recursive function call, print the entered five characters in reverse order. */# Include <stdio. h> # include <stdlib. h> void func (char * Ch); int main () {char STR [6]; gets (STR); func (STR); System ("pause "); return 0;} void func (char * Ch) {If (* Ch! = '\ 0') {func (CH + 1); printf ("% C", * Ch);} else return;}/* [Program 27] Question: the input five characters are printed in reverse order using the recursive function call method. */# Include <stdio. h> # include <stdlib. h> void func (int n); int main () {func (5); System ("pause"); Return 0;} void func (int n) {char ch; ch = getchar (); If (n> 1) func (n-1); putchar (CH);}/* [Program 28] Question: five people sit together, how old is the fifth person? He said he is two years older than 4th. Asked about the age of 4th People, he said he was two years older than 3rd people. Ask the third person, and say that the person is two years older than 2nd. Ask 2nd people, saying they are two years older than the first. Finally, I asked the first person that he was 10 years old. How old is the fifth person? This question is too simple. Do you want to program it? It is estimated that the calculation is performed recursively */# include <stdio. h> # include <stdlib. h> int func (int n); int main () {printf ("5th individuals % d years old \ n", func (5); System ("pause "); return 0;} int func (int n) {If (n = 1) return 10; else return 2 + func (n-1);}/* [Program 29] Question: to give a positive integer of no more than five digits, the requirements are as follows: 1. Calculate the number of digits, and 2. Print the numbers in reverse order. */# Include <stdio. h> # include <stdlib. h> int main () {int n, a, B, c, d, e; scanf ("% d", & N); A = N/10000; B = n % 10000/1000; C = n % 1000/100; D = n % 100/10; E = n % 10; if (! = 0) printf ("this is a 5-digit number. Print it in reverse order: % d \ n", E, D, C, B, a); else if (B! = 0) printf ("this is a 4-digit number. Print it in reverse order as % d \ n", E, D, C, B ); else if (C! = 0) printf ("this is a three-digit number. Print it as % d \ n", E, D, C); else if (D! = 0) printf ("this is a two-digit number, which is printed in reverse order as % d \ n", E, D); else printf ("this is a one-digit number, print in reverse order: % d \ n ", a); System (" pause "); Return 0;}/* [program 30] Question: a five-digit figure, determine whether it is the number of replies. That is to say, 12321 is the number of replies, with the same number of digits and tens of thousands of digits. */# Include <stdio. h> # include <stdlib. h> int main () {int n, a, B, c, d, e; scanf ("% d", & N); A = N/10000; B = n % 10000/1000; C = n % 1000/100; D = n % 100/10; E = n % 10; if (a = E & B = D) printf ("% d is the number of input files. \ n ", n); else printf (" % d is not a return number \ n ", n); System (" pause "); Return 0 ;} /* [Program 31] Question: Enter the first letter of the day of the week to determine the day of the week. If the first letter is the same, continue to judge the second letter. Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday; */# include <stdio. h> # include <stdlib. h> int main () {char ch; CH = getchar (); // eat the return letter switch (CH) {Case 'M ': printf ("Monday \ n"); break; Case 'W': printf ("Wednesday \ n"); break; Case 'F ': printf ("Friday \ n"); break; Case 'T': printf ("unable to judge, then enter the second letter"); CH = getchar (); if (CH = 'U') printf ("Tuesday \ n"); If (CH = 'H') printf ("Thursday \ n"); break; case's ': printf ("cannot be judged And then enter the second letter "); CH = getchar (); If (CH = 'A') printf (" Saturday \ n "); if (CH = 'U') printf ("Sunday \ n"); break; default: printf ("date error");} system ("pause "); return 0;} Question 32-35 is related to the TC-specific graphics library. Give up Question 36 to calculate the prime number, and repeat the previous question. Give up question/* [Program 37: sort the 10 numbers, and then bubble */# include <stdio. h> # include <stdlib. h> # define n 10int main () {int A [n], I, j, TEM; printf ("Please input 10 number: \ n "); for (I = 0; I <n; I ++) scanf ("% d", & A [I]); for (I = N-1; I> 0; I --) for (J = 0; j <I; j ++) if (a [J]> A [J + 1]) {TEM = A [J]; A [J] = A [J + 1]; A [J + 1] = TEM;} for (I = 0; I <n; I ++) printf ("% d", a [I]); System ("pause"); Return 0;}/* [Program 38] Question: calculates the sum of the diagonal elements of a 3*3 matrix */# include <stdio. h> # include <stdlib. h> int main () {int A [3] [3]; int I, S = 0; int * P = (int *); printf ("enter each element of the 3 * 3int matrix: \ n"); for (I = 0; I <9; I ++) scanf ("% d", P ++); for (I = 0; I <3; I ++) S + = A [I] [I]; printf ("the sum of the diagonal elements of the 3*3 matrix: % d \ n", S); System ("pause"); Return 0 ;}/ * [Program 39] Question: There is an array sorted. Enter a number to insert it into the array according to the original rule. */# Include <stdio. h> # include <stdlib. h> int main () {int A [11] = {,}; int I, j, N; scanf ("% d ", & N); for (I = 0; I <10 & n> A [I]; I ++); For (j = 10; j> I; j --) A [J] = A [J-1]; A [I] = N; printf ("the inserted result is \ n"); for (I = 0; I <11; I ++) printf ("% d", a [I]); System ("pause"); Return 0 ;}/ * [Program 40] Question: returns an array in reverse order. This is really so simple. I have a question about whether this is a classic topic */# include <stdio. h> # include <stdlib. h> int main () {int A [10] = {,}, I; printf ("the output result of the array in reverse order is: \ n "); for (I = 9; I> = 0; I --) printf (" % d ", a [I]); System (" pause "); return 0 ;}

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.