Program to find factorial of Number in C++ | Interesting321


factorial of Number in C++:


if a number is given for example 3, the factorial of number 3 is 3*2*1 which means 6.


 The logic of the program:



         The logic of the program is very easy. the given value is assigned in a variable name

n. For loop end with 1, not a 0, it increases the element till the 'n' number and both the

elements are multiply 1*2*3 = 6.

#include< iostream.h >
using namespace std;
int main()
{ 
clrscr();
int n,fact=1;
cout<<"Enter the positive numbers";
cin>>n;
for(int i=1;i<=n;i++)
{
fact=fact*i;
}
cout <<"factorial of the number is %d" << fact ; 
Output:
For download CPP file click below download button:
Download

Recommended Posts:

Post a Comment

0 Comments