#include <stdio.h> double factorial(int nNum) { int i = nNum; double dblRes = 1; while(nNum > 0) { dblRes *= nNum; nNum--; } return dblRes; } int main() { double dblResult = 0; int i = 1; for(; i < 6; ++i) { dblResult += factorial(i); } printf("%f\n", dblResult); return 0; }
#include <stdio.h> int main (void) { int fun (int n); int i,sum=0; scanf("%i",&i); for(;i>0;i--) sum+=fun(i); printf("sum=%i\n",sum); return 0; } int fun (int n) { if(n==0) return 1; else return n*fun(n-1); }
unsigned fac(unsigned n) { if (n == 1) return n; return fac(n - 1) * n; } int main(void) { unsigned i, sum; for (i = 1; i < 6; i++) sum += fac(i); printf("%u\n", sum); return 0; }