Finding the factorial of a number is not so much a difficult task to do, but it becomes very difficult when you have to make a computer understand that ‘You need it for calculating a Factorial‘. Defining in a programming language what a factorial is and using it for making your life easier seems to be a very difficult task.
You can make a program that can calculate a Factorial for you. Many of you already know the syntax or way to calculate Factorial with pen and paper. This is the same method we have to implement in the program.
FIND FACTORIAL OF NUMBER WITH NOTEPAD
The logic to find a factorial of a number is very easy. As factorial is the simple multiplication of numbers, So it doesn’t matter whether you multiply them in increasing order or in decreasing order – the result remains the same. (I’m using simply a For loop here), which goes to the specified number and multiply all numbers coming in-between.
Fact(5) = 5 x 4 x 3 x 2 x 1 = 120 (Traditional Method) Fact(5) = 1 x 2 x 3 x 4 x 5 = 120 (Same Result)
How does it work? – PRINT FACTORIAL OF A NUMBER
You can print the Factorial of any number you want to know, but as CMD has its own limitations – and there is the limit of an integer variable in CMD. (which holds the value of result calculated) As in the above image, we have simply printed the factorial of ‘5’ on the cmd console.
So, we can only print factorial of the first 31 natural numbers!! This is only due to the limitation of CMD variable length. But, we can still make it improved by using various techniques to boost the limit of variables. But, we can leave that for the next version maybe.
From Editor’s Desk
You can download this program, via the link given below. And, Share your opinion about the simple but informative project in the comments section below. I will be waiting for your comments and appreciations. You can also submit your own work – to share it with all other programmers worldwide.
HASH Code - For Verification - (SHA-256)
Keep learning, keep sharing….TheBATeam
Be happy, spread happiness…