2020-05-30 04:23:24 +08:00
|
|
|
#include <stdio.h>
|
2020-05-20 18:10:14 +08:00
|
|
|
int main()
|
|
|
|
{
|
2020-05-30 04:23:24 +08:00
|
|
|
int a[200], n, counter, temp, i;
|
|
|
|
a[0] = 1;
|
|
|
|
counter = 0;
|
2020-05-20 18:10:14 +08:00
|
|
|
printf("Enter a whole number to Find its Factorial: ");
|
2020-05-30 04:23:24 +08:00
|
|
|
scanf("%d", &n);
|
|
|
|
if (n < 0)
|
|
|
|
printf("Cannot Calculate factorials for negative numbers.");
|
|
|
|
else
|
2020-05-20 18:10:14 +08:00
|
|
|
{
|
2020-05-30 04:23:24 +08:00
|
|
|
for (; n >= 2; n--)
|
2020-05-20 18:10:14 +08:00
|
|
|
{
|
2020-05-30 04:23:24 +08:00
|
|
|
temp = 0;
|
|
|
|
for (i = 0; i <= counter; i++)
|
|
|
|
{
|
|
|
|
temp = (a[i] * n) + temp;
|
|
|
|
a[i] = temp % 10;
|
|
|
|
temp = temp / 10;
|
|
|
|
}
|
|
|
|
while (temp > 0)
|
|
|
|
{
|
|
|
|
a[++counter] = temp % 10;
|
|
|
|
temp = temp / 10;
|
|
|
|
}
|
2020-05-20 18:10:14 +08:00
|
|
|
}
|
2020-05-30 04:23:24 +08:00
|
|
|
for (i = counter; i >= 0; i--)
|
|
|
|
printf("%d", a[i]);
|
2020-05-20 18:10:14 +08:00
|
|
|
}
|
|
|
|
return 0;
|
2017-11-02 17:21:48 +08:00
|
|
|
}
|