TheAlgorithms-C/math/factorial_trailing_zeroes.c
Defective Detective 56b72da9fb
chore: move various misc folder... (#1177)
...algorithms to the `math` folder.

Co-authored-by: David Leal <halfpacho@gmail.com>
2022-12-22 11:26:50 -06:00

31 lines
745 B
C

/*
programme for computing number of zeroes at the end of factorial of a given
number n
*/
#include <math.h> //including math.h header file to use pow function
#include <stdio.h>
int main()
{
int i, n, test = 0, count = 0;
// taking input number n
scanf("%d", &n);
// looping from 1 till loop break
for (i = 1;; i++)
{
test =
n /
pow(5,
i); // division of n by ith power of 5(storing in integer form)
if (test !=
0) // condition for zeroes at end corresponding individual ith case
{
count = count + test;
}
else
break; // break the loop for if test=0
}
printf("%d\n", count);
return 0;
}