C language is very simple several questions (or write), relatively simple, mainly have several questions of the data type (for example, the third problem) and the order of the sentence (for example, the second problem) need to pay attention to a small down.
- 1. When the value of the expression S=1*2*3......*n is greater than 150, the value of the smallest n
1 /*2 1. When the value of the expression S=1*2*3......*n is greater than 150, the value of the smallest n3 */4#include <stdio.h>5 voidMain () {6 intn=1, s=1;7 while(s<= Max){8s*=N;9n++;Ten } Oneprintf"%d", N-1); A getch (); -}
- 2. The value of the expression 1/1+1/2+1/3......+1/n is greater than 3 o'clock, and the minimum number of items required
1 /*2 2. The value of the expression 1/1+1/2+1/3......+1/n is greater than 3 o'clock, and the minimum number of items required3 */4#include <stdio.h>5 voidMain () {6 floatn=0, s=0;7 while(s<=3){8n++;9s=s+1/N;Ten //Note the order of accumulation and self-increment, which need to be changed according to the initial value of n One } Aprintf"%d",(int) n); - getch (); -}
3. According to media releases, China's GDP totaled $5.845 trillion in 2010, an increase of 10.1%,
US GDP totaled $14.536 trillion, a growth rate of 3.3%. At a time when the GDP of both countries remained unchanged for 2010 years,
What is the earliest year that China's GDP is expected to exceed US GDP?
1 /*2 3. According to media releases, China's GDP totaled $5.845 trillion in 2010, 10.1% growth rate,3 US GDP totaled $14.536 trillion, a growth rate of 3.3%. At a time when the GDP of both countries remained unchanged for 2010 years,4 What is the earliest year that China's GDP is expected to exceed US GDP? 5 */ 6 //7#include <stdio.h>8 voidMain () {9 floatC=5.845, a=14.536, cg=0.101, ag=0.033;Ten inty= .; One while(c<=a) { Ac+=c*CG; -a+=a*AG; -y++; the } -printf"%d", y); - getch (); -}
- 4. Evaluates the value of the expression S=1+2+3+4......+n, and the value of n is entered by the keyboard
1 /*2 4. Evaluates the value of the expression S=1+2+3+4......+n, and the value of n is entered by the keyboard3 */4#include <stdio.h>5 voidMain () {6 inti,n,s=0;7scanf"%d",&n);8 for(i=1; i<=n;i++){9s+=i;Ten } Oneprintf"%d", s); A getch (); -}
- 5. Find the expression s=1!+2!+3!...... +n!,n typed by the keyboard
1 /*2 5. Find the expression s=1!+2!+3!...... +n!,n typed by the keyboard3 */4#include <stdio.h>5 voidMain () {6 inti,j=1, s=0, N;7scanf"%d",&n);8 for(i=1; i<=n;i++){9j*=i;Tens+=J; One } Aprintf"%d", s); - getch (); -}
A very simple question of C language