#include
int main(){ int i, j, n = 0, sum; for (i = 3; i <= 1000; i++) { sum = 0; for (j = 1; j < n - 1; j++) if (n % j == 0) sum = sum + j; if (i == sum) { printf("%d", i); n++; if (n % 5 == 0) printf("n"); } } printf("n%dn", n); return 0;}
1.定义整数变量i,j,n=0,sum
2.i=33.i<=1000值为真走4,否则输出n,结束4.sum=05.j=16.j
#include
int main(){ int i, n = 0; for (i = 1900; i <= 2000; i++) { if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0) { printf("%dt", i); n++; if (n % 3 == 0) { printf("n"); } } } return 0;}
1.定义整数变量i,n=0
2.i=19003.i<=2000值为真走4,否则结束4.i % 4 == 0 && i % 100 != 0 || i % 400 == 0值为真走6,否则转55.i++返回36.输出i7.n++8.n%3
#include
int main(){ int i, a, b, c, n = 0; for (i = 100; i <= 999; i++) { a = i / 100; b = (i - a * 100) / 10; c = i % 10; if (a * a * a + b * b * b + c * c * c == i) { printf("%dt", i); n++; if (n % 2 == 0) { printf("n"); } } } return 0;}
1.定义整数变量i,a,b,c,n=0
2.i=100
3.i<=999值为真走4,否则结束
4.a = i / 100
5.b = (i - a * 100) / 10
6.c = i % 10
7.a * a * a + b * b * b + c * c * c == i值为真走9,否则转8
8.i++返回3
9.输出i
10.n++
11.n%2==0值为真输出换行返回8,否则转8
#include
int main(){ int k = 1, i, n, t; float e = 1, s = 1; scanf_s("%d", &n); do { t = 1; for (i = 1; i <= k; i++) t = t * i; e = e + 1.0 / t; k++; } while (k <= n); printf("%.2f", e); return 0;}
1.定义整数变量k=1,i,n,t;小数变量e=1,s=1
2.给n赋值3.t=14.i=15.i<=k值为真走6,否则转86.t=*i7.i++返回58.e=e+1.0/t9.k++10.k<=n值为真返回3,否则输出e
#include
int main(){ float y, s = 1, x, xx = 1, a = 1, i = 1; scanf_s("%f", &x); do { a = -a; i++; xx = xx * x; y = i / xx; s = s + a * y; } while (y > 0.00001); printf("%f", s); return 0;}
1.定义小数变量y,s=1,x,xx=1,a=1,i=1
2.给x赋值
3.a=-a
4.i++
5.xx = xx * x
6.y = i / xx
7.s = s + a * y
8.y>0.00001值为真走3,否则输出s
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)