53 lines
1004 B
Plaintext
53 lines
1004 B
Plaintext
|
/*
|
|||
|
file name: factorUsingRecursive.c
|
|||
|
Description: <20>Q<EFBFBD>λ<EFBFBD><CEBB>j<EFBFBD>I<EFBFBD>s<EFBFBD>p<EFBFBD><70> N <20><><EFBFBD><EFBFBD>
|
|||
|
*/
|
|||
|
|
|||
|
#include <stdio.h>
|
|||
|
#include <ctype.h>
|
|||
|
#include <stdlib.h>
|
|||
|
|
|||
|
/* <20><><EFBFBD>ƭ쫬<C6AD>ŧi */
|
|||
|
long Factorial(long);
|
|||
|
void flushBuffer(void);
|
|||
|
|
|||
|
int main()
|
|||
|
{
|
|||
|
char ch;
|
|||
|
unsigned long n;
|
|||
|
|
|||
|
printf("-----Factorial counting Using Recursive----");
|
|||
|
do {
|
|||
|
printf("\nEnter a number( 0<=n<=12 ) to count n!: ");
|
|||
|
scanf("%ld", &n);
|
|||
|
flushBuffer();
|
|||
|
|
|||
|
/* n <20><><EFBFBD>Ȧb<C8A6>@<40><><EFBFBD>t<EFBFBD>Τ<EFBFBD><CEA4>W<EFBFBD>L 13 <20>|<7C><><EFBFBD><EFBFBD> overflow <20>o<EFBFBD>줣<EFBFBD><ECA4A3><EFBFBD>T<EFBFBD><54><EFBFBD><EFBFBD> */
|
|||
|
if (n < 0 || n >12)
|
|||
|
printf("<22>W<EFBFBD>X<EFBFBD>d<EFBFBD><64>!\n");
|
|||
|
else
|
|||
|
printf("%ld! = %ld\n", n, Factorial(n) );
|
|||
|
|
|||
|
printf("Continue(y/n)? ");
|
|||
|
ch = toupper(getchar());
|
|||
|
} while (ch == 'Y');
|
|||
|
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
/* <20>Q<EFBFBD>λ<EFBFBD><CEBB>j<EFBFBD>I<EFBFBD>s<EFBFBD>ۤv<DBA4>p<EFBFBD><70>N <20><><EFBFBD><EFBFBD>*/
|
|||
|
long Factorial(long n)
|
|||
|
{
|
|||
|
if ( n == 1 || n== 0)
|
|||
|
return (1);
|
|||
|
else
|
|||
|
return( n * Factorial(n-1));
|
|||
|
}
|
|||
|
|
|||
|
void flushBuffer()
|
|||
|
{
|
|||
|
while (getchar() != '\n') {
|
|||
|
continue;
|
|||
|
}
|
|||
|
}
|