I wonder below quetion
input of 1~n
if you select 3,
123
132
213
231
312
321
count is 3 factorial....hm..
give me hint~
thanks....
I wonder below quetion
input of 1~n
if you select 3,
123
132
213
231
312
321
count is 3 factorial....hm..
give me hint~
thanks....
Are you looking for a way to calcuate a factorial? If so, here's a recursive one.
Code:#include <stdlib.h> #include <stdio.h> int factorial(int n); int main(void) { int n; printf("Enter number for which to calculate factorial:"); scanf("%d",&n); printf("%d! = %d\n",n,factorial(n)); return 0; } int factorial(int n) { if (n == 0) return 1; else return n*factorial(n-1); }
Last edited by swoopy; 03-30-2002 at 01:20 AM.
Itīs not the optimal solution to solve this simple problem recoursively.
The recoursion wastes a high amount of your stack memory.
better:
klausiCode:unsigned int factorial(int n); { unsigned int fact=1; for(;n>1;fact*=n, n--) ; return fact; }
When I close my eyes nobody can see me...