C++ Program to find Factorial of number using Function

ad+1

In this program we will declare an integer and ask user to enter its value. Then we will pass that integer to function where we will find factorial using for loop.

 Program:

// Program By http://solutionscpp.blogspot.com
// Author Mansoor Ahmed
// GMail ID: secguy000@gmail.com

 
#include<iostream>
using namespace std;

int fact(int n);          //function prototype

int main()
{

 int n=0, result=0;

 cout<<"Enter Number: ";
 cin>>n;

 result=fact(n);
 cout<<"Factorial of " <<n <<" is: " <<result <<endl;

}

int fact(int n)   //function definition
{

 int f=1;

 for(int i=1; i<=n; i++)
 {
  f=f*i;
 }

 return f;

}


Output:

4 comments: Leave Your Comments

  1. This code is helpful but I want some Example of C++ Programs;

    Print Star pattern in C++
    Print number pattern in C++
    Factorial Program in C++

    ReplyDelete
  2. This is stunning! I am passed up the nature with this astounding.I've perused a lot of articles, financial firms one of the best ones that I've perused. Keep on providing more articles this way.solve your afp problems

    ReplyDelete
  3. I found nice article in your blog.thank you for useful info
    .

    ReplyDelete