请好友帮忙看下,给我一个答案
怎样编写如下程序输入一个n,求1!+2!+3!.......n!。注意(n小于20)
root@~ #cat jc.c #include <stdio.h> int main (void) { int n,i; long int sum=0; long int jc (int n); printf ("Enter a digit:"); scanf ("%i",&n); if (n<1||n>20) { printf ("Out of rang !\n");return 1; } for(i=0;i<n;i++) { sum+=jc(i); } printf ("sum is %li\n",sum); return 0; } long int jc (int n) { long int result; if(n==0) return result=1; else return result=n*jc(n-1); } root@~ #
#include <stdio.h> int main (void) { int n,i; long int sum=0; long int jc (int n); printf ("Enter a digit:"); scanf ("%i",&n); if (n<1||n>20) { printf ("Out of rang !\n");return 1; } for(i=1;i<=n;i++) { sum+=jc(i); } printf ("sum is %li\n",sum); return 0; } long int jc (int n) { long int result; if(n==0) return result=1; else return result=n*jc(n-1); }