Skip to main content


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:

Special Case

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:

Gama 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.


Popular posts from this blog

How to Make Blink LED with PIC16F628A

How to Make Blink LED With PIC16F628A In this project tutorial, we are going to make blink-led projects with a pic microcontroller. After you read this tutorial you can build a PIC microcontroller project with XC8 on MPLAB IDE. We are going to make 3 different blinking projects. These projects are basic. Just learn how to make a basic project with a PIC microcontroller. You can see below which projects we are going to make; Blinking LED with 1s delay, LED with button, Blinking LED with a button.

Ultrasonic Sensor HC-SR04 With PIC Microcontroller

How Ultrasonic Sensor Works An ultrasonic sensor is a very useful sensor that measures distances with sounds. We used the PIC16F628A microcontroller for this project. This microcontroller has TMR1 which we are going to use. We need 2 I/O pins for TRIG and ECHO pins. For showing distance, we used an LCD. For more information about the LCD library and usage click the button below. LCD Interfacing with PIC Using XC8

DC Motor Speed Control With PIC16F628A

DC Motor Speed Control Simulation In this project, we will control the speed and direction of a DC motor using the PIC16F628A microcontroller. We will write the software in MPLAB IDE with the XC8 language that will send a PWM signal to L293D to control the motor. Finally, we will simulate it through the Proteus software. PWM (Pulse Width Modulation) You can get more information about the PWM signal from the link above. Now let’s examine the L293D motor driver.