mlfk.net
当前位置:首页 >> C语言编程题:输入一个正整数n,输出1+1/2+2/3+3/4... >>

C语言编程题:输入一个正整数n,输出1+1/2+2/3+3/4...

#includeint main(){ int n; double sum=0;//记录总和初始值为0 printf("输入n的值:"); scanf("%d",&n); for(int i=1;i

#include main() { int n,i; double r=0,x; scanf("%d",&n); for(i=1;i

#include int main() { int n,sum=0; scanf("%d",&n); while(n) { sum+=n%10; n/=10; } printf("%d\n",sum); return 0; }

#include int main(void) { int n; scanf("%d", &n); printf("", (1 + n) * n / 2); return 0; }

#include"stdio.h" int jiechen(int n) { int z = 0; if (n == 1) { z = 1; } else { z = n * jiechen(n - 1); } return z; } main() { printf("输入n:\n"); int n = 0; scanf("%d", &n); int z = jiechen(n); printf("结果是:%d", z); }

main(){ int k,flag=1,n;float s=0;scanf("%d",&n);for(k=1;k

其实用递归算更简单,再给你一个吧 #include //由于标准math.h中没有求阶乘函数,所以自己写一个吧 int jiecheng(int n) { if(n

#include int main() { double sum=0,temp; int n,i,j; scanf("%d",&n); for(i=1;i

#include int main(void) { int i, sum = 0; printf("Enter an positive integer: "); scanf("%d", &i); while (i > 1) { sum += ((i - 1) + i); i--; } printf("The result is %d.\n", sum); return 0;}

double sum = 0; int temp=1; f=1; m=1; for(int i=0;i

网站首页 | 网站地图
All rights reserved Powered by www.mlfk.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com