In this article, we will describe the factorial and write a sample program written in c.
To find the factorial of a number, we multiply the integer from that number by 1. So the factorial of a number;

in the form. These should be n natural numbers. 1! and 0! for the following:

Now you can think of: Is there a factorial of decimal or negative numbers? The answer is yes. You can search the gamma function for this. Gamma function:

is defined as.
Finding Zero Number at the End of Factorial
If n> = 5, n! is always zero at the end. The larger the number, the greater the number of zeros. So how do we find that number 0? In order for a number to be 0 at the end, it must have a factor of 5 and 2. For example, the multipliers of the number 120 are 2 * 2 * 2 * 3 * 5. As can be seen, the number 120 has at least one multiplier of 2 and 5. Now 6! let’s examine. To find the number zero, we only need to look at how many 5 are. Because 2 is always more than 5 numbers. 6! = 6 * 5 * 4 * 3 * 2 * 1 and 7! = 2 * 2 * 2 * 2 * 3 * 3 * 5; Since there is only 1 in the multipliers, there is 1 zero at the end of this number. Can we find out how many 5 are in this factorial before we find their multipliers? Of course yes. For this, we divide the number by 5 until it is less than 5. So if we divide 7 by 5, the result will be decimal, but we get only the full part of that number. So we say 7/5 = 1. That’s 7! there was only one 5 in the number. Now 60! Let’s examine: 60/5 = 12 => 12/5 = 2, the number is less than 5 now we collect the results. 12 + 2 = 14. In this case 60! there are 14 multiples of 5 and there are 14 zeros at the end of this number.
Let’s say we have a lot of work to do, and we don’t want to do it all the time. We can write a program for this. Our program is written in c language. You can do this in different languages.
C Source Code :::
#include <stdio.h> int main () { unsigned int num, zeroNum; while (1) { for (zeroNum = 0, scanf ("%d", & num); num> 4; num /= 5, zeroNum += num); printf ("%d \n", zeroNum); } return 0; }
Program Output :::

When you compile and run these codes with a c compiler: you will be prompted to enter a number in the console, which will print the number zero at the end of the factorial of that number. I hope it was helpful.
Note: Repl is a website in which you can write any programming language and compile your code.

Comments
Post a Comment