This C++ Program computes factorial of a given integer. Here the factorial is computed by multiplying all the numbers upto the given input.
Here is source code of the C++ program which computes the factorial of a given number. The C++ program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C++ program to compute factorial of a given integer
*/
#include<iostream>
using namespace std;
int main()
{
int fac;
long long val = 1;
cin >> fac;
cout << endl;
for (int i = 2; i <= fac; i++)
val = val * i;
cout << "The factorial of " << fac << " is " << val << endl;
return 0;
}
$ g++ main.cpp $ ./a.out Enter the integer : 10 The factorial of 10 is 3628800
Sanfoundry Global Education & Learning Series – 1000 C++ Programs.
advertisement
advertisement
If you wish to look at all C++ Programming examples, go to C++ Programs.
Next Steps:
- Get Free Certificate of Merit in C++ Programming
- Participate in C++ Programming Certification Contest
- Become a Top Ranker in C++ Programming
- Take C++ Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Apply for Information Technology Internship
- Buy C++ Books
- Apply for Computer Science Internship
- Apply for C++ Internship
- Practice Programming MCQs