Simple factorial program in cpp




















Find G. D Using Recursion. Convert Binary Number to Decimal and vice-versa. Convert Octal Number to Decimal and vice-versa. Related Topics Find Factorial. Calculate Sum of Natural Numbers. Share on:. Also factorial of 0 and 1 is 1. Recursion refers to the process when a function calls itself inside that function directly or indirectly or in a cycle. If you want to learn more about recursion in detail, click here. Although it is for C programming but the theory concept of recursion is the same for all programming languages.

Learn more. Asked 7 months ago. Active 7 months ago. Viewed times. Improve this question. Amarnath Banerjee Amarnath Banerjee 1 2 2 bronze badges. Why do you need it? For an approximation, use double. For an exact value, you need extended-precision software. You will never store it in an int , or any other native type.

Then we have mentioned the condition that variable I should be equal to and less than number which is entered by the user. Then we have mentioned the increment condition to increase the value of variable I each time at the iteration process.

Explanation of the above program: Here we have used the recursion method to calculate the factorial. The recursion method is quite similar to the function method. The recursion method is mostly used to solve the problem easily. Here we have declared factorial as a function and pass num as a parameter. In the factorial method, we have used the if-else statement to check whether the entered number is positive or not as we have used in the first example.

Then we have called the factorial method where statements for factorial are executed. Explanation of the above program: Here to calculate factorial for number we have used the function method. First, we create a factorial function and pass n as a parameter to store the number value.



0コメント

  • 1000 / 1000