C++ program to find Factorial of a number

 //C++ program to find factorial of number using function
#include <iostream>
using namespace std;
void fact(int a)
{
   int num=1;
   for(int i=1;i<=a;i++)
   {
      num=num*i;
   }
   cout<<"\nThe factorial of the number "<<a<<" is = "<<num;
}


int main()
 {
 int num;
 cout<<"Enter a number to find its Factorial ";
 cin>>num;
 fact(num);

 return 0;
}

No comments:

Post a Comment