Now you can Subscribe using RSS

Submit your Email

factorial program in cpp using function

A LIFE ABK







c/c++ program solver,c++ program, new program, program code ,programing question

factorial program in cpp using function, factorial program



In this example, we will explain to you write a factorial program in c++. To understand this topic it is necessary to have knowledge of basic CPP, function, and loop. Please read this article carefully so that you can understand the factorial program in c++.



First of all, you can imagine the output screen then build your logic.


 Enter N number : 5
factorial of 5 is 120














You must have this knowledge




Program logic


Create a variable named n of int type. Then take input into it.

After taking the input call the function named pro. And pass n variable to it.

Create a fact name variable inside the pro function and assign 1 to it.

Then put a loop. And i = 1 in the condition of the loop. And run up to i<= n. And when the condition of the loop is true. So multiply the fact with i variable inside the loop. result Assign to the fact.

This way the loop will continue. Until 1 is equal to n.


After the loop is over, the return statement will run. then The cursor will move on from where the function call was made. After this, the result will be printed.



Source code factorial program in cpp using function


Output Screen

factorial program in cpp using function, factorial program



Recommended Post






😊

Now next you are, write your code in the comment below.😊

A LIFE ABK / Author & Editor

0 Comments:

Post a Comment

Please do not enter any spam link in the comment box.

Coprights @ 2021-2022, Ancient Code Designed By AbK