2020-05-29 23:23:24 +03:00
|
|
|
#include <stdio.h>
|
2020-05-20 13:10:14 +03:00
|
|
|
int main()
|
|
|
|
{
|
2020-05-29 23:23:24 +03:00
|
|
|
int a[200], n, counter, temp, i;
|
|
|
|
a[0] = 1;
|
|
|
|
counter = 0;
|
2020-05-20 13:10:14 +03:00
|
|
|
printf("Enter a whole number to Find its Factorial: ");
|
2020-05-29 23:23:24 +03:00
|
|
|
scanf("%d", &n);
|
|
|
|
if (n < 0)
|
|
|
|
printf("Cannot Calculate factorials for negative numbers.");
|
|
|
|
else
|
2020-05-20 13:10:14 +03:00
|
|
|
{
|
2020-05-29 23:23:24 +03:00
|
|
|
for (; n >= 2; n--)
|
2020-05-20 13:10:14 +03:00
|
|
|
{
|
2020-05-29 23:23:24 +03: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 13:10:14 +03:00
|
|
|
}
|
2020-06-28 18:25:37 +03:00
|
|
|
for (i = counter; i >= 0; i--) printf("%d", a[i]);
|
2020-05-20 13:10:14 +03:00
|
|
|
}
|
|
|
|
return 0;
|
2017-11-02 12:21:48 +03:00
|
|
|
}
|