求n的阶乘各位数之和,
1<n<=50求各个位的数字的和
程序代码:#include <stdio.h>
#include <string.h>
#define max 3000
int f[max];
int main() {
int i, j, n, c, s, sum;
scanf("%d", &n);
f[0] = 1;
for(i = 2; i <= n; i++) {
c = 0;
for(j = 0; j < max; j++) {
s = f[j] * i + c;
f[j] = s % 10;
c = s / 10;
}
}
for(j = max - 1; j >= 0; j--)
if(f[j]) break;
for(i = j; i >= 0; i--) printf("%d", f[i]);
printf("\n");
sum = 0;
for(i = j; i >= 0; i--) sum += f[i];
printf("%d\n", sum);
return 0;
}
给出我代码,有兴趣的可以想想...
