1到20的阶乘,我是新手
#include<math.h>#include<stdio.h>
main()
{
int a=1,b=1,c=1;
float i=0.0,d=0.0001;
while(fabs(1./a)>=fabs(d))
{
i=i+1/a;
if(b%2!=0)
c=-1;
else c=1;
a+=2;
a=a*c;
b++;
}
printf("%f\n",i);
}
#include <stdio.h> int main(void) { long long result = 1; for (int i = 1; i <= 20; i++) { result *= i; printf("%2d!=%lld\n", i, result); } return 0; }
#include "stdio.h" void main(){ int i , j; double t; for(i = 1 ; i <= 20 ; i++){ for(t = 1 , j = i ; j > 1 ; j--) t = t * j ; printf("1"); for(j = 2 ; j <= i ; j++) printf("*%d",j); printf("=%.0lf\n",t); } }
#include <stdio.h> int main(void) { int i; long long j = 1; for (i = 1; i <= 20; i++) j *= i; printf("%lld", j); return 0; }
[此贴子已经被作者于2019-1-14 20:42编辑过]
[此贴子已经被作者于2019-1-15 17:53编辑过]