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

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


factorial of Number in C++:

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




Logic of the program:

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 increase the element till the n number and both the
elements are multiply 1*2*3 = 6.


#include<iostream.h>
#include<conio.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 a given number is = "<<fact;
return 0;
getch();
}


Output:



For download cpp file click below download button:

Download



No comments:

Post a Comment