Input : 6 = 2 * 3 * 4 * 5 = 120 = Trailing zeros = 1
Output : 1
For more detailed tutorial :
http://www.purplemath.com/modules/factzero.htm
#include <stdio.h>
void main()
{
long n =0;
long div = 5;
long sum = 0;
printf("Enter N! value:");
scanf("%ld",&n);
while(n >= div)
{
sum += n/div;
div *= 5;
}
printf(" Output is :%ld", sum);
}
Importance of finding the trailing zeros will be useful in floating
point representation.
It will be used to represent floating numbers
as 2 * (10 ^ 3)
mantissa: 2
exponent: 3
Same will be used to represent negative numbers in floating point
representation;
2 * (10 ^ -3)
No comments:
Post a Comment