Sunday, August 23, 2015

Factorial of a number using functions

Q. 97 Write a C++ program to find the Factorial of a number using functions.



Copy Code:

#include <iostream>
using namespace std;

int main()

{
  int a; int fact( int n );

  cout << " Enter a Number : ";
  cin >> a;
  cout << " Factorial of " << a << " = " << fact (a);
  
  return 0;
}

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



No comments:

Post a Comment