mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-29 00:33:14 +03:00
56b72da9fb
...algorithms to the `math` folder. Co-authored-by: David Leal <halfpacho@gmail.com>
32 lines
745 B
C
32 lines
745 B
C
#include <stdio.h>
|
|
int main()
|
|
{
|
|
int a[200], n, counter, temp, i;
|
|
a[0] = 1;
|
|
counter = 0;
|
|
printf("Enter a whole number to Find its Factorial: ");
|
|
scanf("%d", &n);
|
|
if (n < 0)
|
|
printf("Cannot Calculate factorials for negative numbers.");
|
|
else
|
|
{
|
|
for (; n >= 2; n--)
|
|
{
|
|
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;
|
|
}
|
|
}
|
|
for (i = counter; i >= 0; i--) printf("%d", a[i]);
|
|
}
|
|
return 0;
|
|
}
|