0

How to find the factorial of a number??

12th Jul 2024, 12:36 PM
Haram Abbas Lar
Haram Abbas Lar - avatar
6 odpowiedzi
+ 3
Ayush Raj , it is not seen as very helpful when we are going to post a ready-made code, as long as the op has not shown his attempt here. it is more helpful to give hints and tips, so that the op has a chance to find a solution by himself.
12th Jul 2024, 6:56 PM
Lothar
Lothar - avatar
+ 5
the factorial of 4 is 4*3*2*1. you can use a loop or recursion. if you need help with your code, show your attempt.
12th Jul 2024, 12:52 PM
Lisa
Lisa - avatar
+ 3
First I wanted to explain about factorial. The basic formula to find a factorial is n!= n*(n-1)*(n-2)*(n-3)*(n-4)*(n-5)*(n-6)..... suppose we need to find factorial of 5 then we use the formula I.e 5*(5-1)*(5-2)*(5-3)*(5-4)=5*4*3*2*1 =120 symbol of factorial that used in most of the time is !
12th Jul 2024, 3:21 PM
Ayush Raj
+ 2
In c++20, you can use the gamma function from the cmath header, it's more concise. For any number, N, it's factorial is double factorial = std::tgamma(N + 1); Remember to import the <cmath> header
12th Jul 2024, 2:39 PM
Melle
+ 2
Programming logic int f=1,n=5; while(n>0) { f=f*n;//f=1*5 I.e5 is stored in f n--; //n=n-1i.e n=5-1,n=4 } printf("The factorial of 5 =%d",f);
12th Jul 2024, 3:31 PM
Ayush Raj
+ 1
Thank you
12th Jul 2024, 6:13 PM
Haram Abbas Lar
Haram Abbas Lar - avatar