Learn to find the factorial using C Program

in #factorial2 years ago

Today we will learn to find a factorial of a number in C program in very simple steps. Based on the memory that a compiler support it will vary upto which number you will be able to find factorial of.

For example finding a factorial of 500000 might give you an error if you are not using a modern compiler. Turbo C and some outdated compiler will simply hang your system to execute such program.

Let us see how we can print the factorial below :

Screenshot 2023-01-14 235657.png

Copy the code from below :

#include <stdio.h>

int main() {
int num, factorial = 1;
printf("Enter a number: ");
scanf("%d", &num);

for (int i = 1; i <= num; i++) {
factorial *= i;
}
printf("The factorial of %d is %d", num, factorial);
return 0;
}

Let us look at the example below :

Screenshot 2023-01-14 235723.png

In this example, the user enters the number 5 as input, and the program calculates the factorial of 5 (which is 12345 = 120) and prints it out to the screen.

It's important to note that the factorial of a number can be very large and depending on the number and hardware it might not be able to compute and store it in the memory.

If you also want to learn coding then find your teacher according to your language. For me i am comfortable with hindi language and follow hindi teachers.

You can refer to my teacher below in case you are also comfortable with hindi.

Source

I will soon call myself a trader and a small programmer together.

Happy trading and keep learning what you love.

Coin Marketplace

STEEM 0.21
TRX 0.20
JST 0.034
BTC 99163.21
ETH 3283.22
USDT 1.00
SBD 3.05