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 : 5factorial 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.
😊
Now next you are, write your code in the comment below.😊
0 Comments:
Post a Comment
Please do not enter any spam link in the comment box.