First, pay attention to the two-level C programming questions.
1. Value calculation class
This type of probability is relatively large, so it must be noticed that this type is not difficult but careful.
1.1.
First of all, know how to know how a number m is the number, its method is as follows:
For (int K = 2; k { IF (m% k == 0) { Break; } } There are only two cases of this cycle, one is to perform the BREAK statement; the other is that the circulation condition is not satisfied, in which the former one is to indicate that M is not a prime number, and the latter is to indicate that M is the number of prime. example 1. Please prepare a functionality FUN (), its function is: calculating and outputting the sum of the squares of the number of all prime numbers between 3 to n. Note: Some source programs have been given. Do not change the contents of the main function main (). Question procedure: #include #include Double Fun (int N) { } Main () { Int n; Double Sum; Printf ("/ n / ninput n: D / N"); Scanf ("% d", & n); SUM = Fun (N); Printf ("/ N / NTHE SUM =% F / N / N", SUM); } This question is difficult: 1. Judgment a number of pixels; 2. Calculate a positive square root. Reference answer: Double Fun (int N) { INT M, K, I; Double S = 0.0; For (m = 3; m ) { K = SQRT (M); For (i = 2; i <= k; i ) { IF (m% k == 0) { Break; } } IF (i> = k 1) / * is actually judging, whether it is executed; statement * / {/ * If a break; statement is performed, then i is <= k * / S = SQRT (m); / * If there is no execution, M is the number of prime * / } / * If you want to change the condition for a non-quantile operation * / } Return S; } 1.2. Equation seeks root (see other reference books) 1.3. N items before the column and The formula of this type looks very complicated, it seems that it is not going to start, in fact, its law is very single, only by one cycle is generally obtained. This type of question is always given the number of items and sum questions, and the solving process is to complete the stored unit into 0, and the cyclic variable sets the initial value (generally 1 or 0). The cyclic body is divided into two steps. The first step is to identify the general term and subscript of the grade, and then utilize the value accumulated or multiplied by the previous item or the molecule or denominner. Example 2. Please prepare a functionality of FUN (), which is: S = 1 1 / (1 2) 1 / (1 2 3) ... 1 / (1 2 3 ... N) For example: if n = 11, the S value is 1.833333. Note: Some source programs have been given. Do not change the contents of the main function main (). Question procedure: #include #include #include { } Main () { Int n; Double S; CLRSCR (); Printf ("/ N / NINPUT N:"); Scanf ("% d", & n); S = Fun (n); Printf ("/ N / NTHE S =% f / n / n", s); } This question is difficult to find the relationship between the general item and the subscript. Reference answer: Double Fun (int N) { INT I; Float s = 1.0, t = 1.0; For (i = 3; i <= n; i ) { T = i; s = (1 / t); } Return S; }