Factorial Using Function Example Program In C++
Definition
In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,
6! = 6 x 5 x 4 x 3 x 2 x 1 = 720
The value of 0! is 1, according to the convention for an empty product.
For Loop Syntax
for (initialization; condition; increment/decrement)
{
}
//for Factorial
for (int counter = 1; counter <= n; counter++) {
fact = fact * counter;
}
Factorial Using Function Example Program
/* Example Program For Factorial Value Using Function In C++
little drops @ thiyagaraaj.com
Coded By:THIYAGARAAJ MP */
#include<iostream>
#include<conio.h>
using namespace std;
//Function
long factorial(int);
int main() {
// Variable Declaration
int counter, n;
// Get Input Value
cout << "Enter the Number :";
cin>>n;
// Factorial Function Call
cout << n << " Factorial Value Is " << factorial(n);
// Wait For Output Screen
getch();
return 0;
}
// Factorial Function
long factorial(int n) {
int counter;
long fact = 1;
//for Loop Block
for (int counter = 1; counter <= n; counter++) {
fact = fact * counter;
}
return fact;
}
Sample Output
Enter the Number :6
6 Factorial Value Is 720
C++ Common Example Programs
- Factorial Using Loop Example Program In C++
- Factorial Using Function Example Program In C++
- Factorial Using Recursion Example Program In C++
- Find Prime Number ( Method1 ) Example Program In C++
- Find Prime Number ( Method2 ) Example Program In C++
- Fibonacci series Example Program In C++
- Example Program For Multiplication Value Using For Loop In C++
- Area Of Circle Example C++ Program
- Area Of Square Example C++ Program
- Area Of Rectangle Example C++ Program
- Odd Or Even Example C++ Program
- Sum of Digits Example C++ Program
- Circumference Of Circle C++ Example Program
- Simple C++ program for print the sum of all odd numbers from 1 to n
- Simple Program for Convert Feet to Inches In C++ Programming
- Odd Or Even Example C++ Program Using function
Read More Articles
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Example Program For Copy Constructor In C++
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Factorial Using Function Example Program In C++
- Simple Example Program For Constructor Overloading In C++
- Simple Example Program For Constructor In C++
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program for Inline Function Using C++ Programming
- Simple Program for Read user Input Using cin
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Simple Program for Multiple Inheritance Using C++ Programming
- Do While Loop Example Program In C++
- Simple Copy Constructor Example Program For Find Factorial In C++
- Simple Program for Function Template Using C++ Programming