int main(){ int i,n;long a=0,b=0;printf("输入n\n");scanf ("%d",&n);for (i=1;i<=n;i++){ a=i*i;printf ("%d*%d=%ld\n",i,i,a);} for (i=1;i<=n;i++){ b=i*i*i;printf ("%d*%d*%d=%ld\n",i,i,i,b);} return 0;} 注意数据类型,当心溢出~...
int n;scanf("%d",&n);for(i = 1; i< n; i++){ printf("%d\n",i);} return 0;}
printf("%d! = %d\n", --j, nn);} return 0;}
可以用C语言解决:include<stdio.h> int main(){ int i,n,mass=1;printf("please enter number N\n"); ---确定 n 的个数--- scanf("%d",&n);for(i=1;i<=n;i++) ---循环乘,积赋给mass { mass=i*mass;} printf("%d",mass); ---输出乘积mass 的大小 printf...
include <stdio.h> int fac(int n);int main(void){ int n;printf("输入要计算阶乘的数:");scanf("%d",&n);if(n<0)printf("请输入非负数\n");else printf("%d的阶乘是:%d\n",n,fac(n));return 0;} int fac(int n){ if(n<2)return 1;else return n*fac(n-1);} ...
今天给大家分享如何用C语言计算1!+2!+···n!值。工具/原料 vc++编译器 方法/步骤 1 用for循环来计算#include<stdio.h>int main(){int n,b,c,x,y;y=0;printf("请输入一个数:");scanf("%d",&n);for(b=1;b<n+1;b++){for(c=1,x=1;c<=b;c++)x=x*c;y=y+x;}printf("1!+2...
include<stdio.h>int main(void){ int n,s=0,i; scanf("%d",&n); for(i=1;i<=n;i++) s+=i; printf("s=%d",s);}
include <iostream>#include <string>using namespace std;int main(){ int a, sum; sum = 0; for (a==1; sum >= 0;a++) { sum = sum+a; if (sum >= 5050) break; } cout << a << endl;}sum 应该大于等于0 ...
int main(){ long i,n,m,sum=0 scanf("%d",&n);for(i=m=1;i<=n;i++);{ m*=i;sum+=m;} printf("%d\n",sum);return 0;} 例如:include <stdio.h> /* 通过递归计算一个数的回阶乘 */ int factorial(int num){ if (num==1)return 1;else return (num * ...
include <stdio.h>int main(){int n;int i = 1;int sum = 0;printf("请输入一个数:");scanf("%d",&n);while(i<=n){sum += i;i++;}printf("1到%d之间数字相加的和为:%d",n,sum);return 0;}