Simple Example Program for Function to Find Factorial In C++
On this page (6sections)
About this program
This is an example program in c function example programs. Read the concept first: C++ Function Basics, then study the code and output below.
Definition
A function is like a black box. It takes in input, does something with it, then spits out an answer.
Syntax
return_type function_name(argumnent)
{
// body Of the Function
}
Simple Example Program Of Function Find Factorial Number
/* Example Program For Simple Example Program Of Function Find Factorial Number In C++
little drops @ thiyagaraaj.com
Coded By:THIYAGARAAJ MP */
#include<iostream>
#include<conio.h>
using namespace std;
// Simple factorial Function
int factorial(int var) {
int fact = 1;
for (int i = 1; i <= var; i++)
fact = fact * i;
return fact;
}
int main() {
cout << "5 Factorial Number :" << factorial(5);
getch();
return 0;
}
Sample Output
5 Factorial Number :120
Related Pages
Learn the concept first, then study the code:
- C++ Programs — Browse all C++ Programs.
- C++ Function Basics — Tutorial — declaring and calling functions in C++.
- Simple Example Program for Function In C++ — More in c function example programs.
- Simple Example Program for Function Find Smallest Number In C++ — More in c function example programs.