BeginnersBook.in

Programming For Geeks

  • Home
  • All Tutorials
    • Learn C
    • Learn Python
  • Programs
    • Java Programs
    • C++ Programs
    • C Programs
  • Algorithms
    • Sorting
  • MCQ’s
    • MySQL
    • Operating System
  • WordPress
    • Genesis Pro Themes
    • Blogs
  • Tools
    • Direct Download Link Generator
    • HTML Compiler
  • How to
    • Web Examples
  • Write For Us

C++ Program to Find Factorial of a Number

May 14, 2018 By Mr. Robot

In this program will learn how to find the factorial of a number using for loop. The factorial number is positive integer n is equal to 1*2*3*…n.

Factorial of negative number can not be found and factorial of 0 is 1

Example: Find Factorial of a Number

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
using namespace std;
 
int main()
{
    int n;
    long factorial = 1;
 
    cout << "Enter a positive integer: ";
    cin >> n;
 
    for(int i = 1; i <= n; ++i)
    {
        factorial = factorial * i;
    }
 
    cout << "Factorial of " << n << " = " << factorial;
    return 0;
}
When you run the program, the output will be following:
1
2
Enter a positive integer: 5
Factorial of 5 = 120

Filed Under: C++ Examples

Related Posts

  • C++ Program to Check Whether Number is Positive, Negative or Zero
  • C++ Program to Find Inverse of a Matrix
  • C++ Program to Divide Two Numbers Without using ‘/’ Operator

Recent Posts

  • Download Grand Theft Auto: Vice City Audio File | Highly Compressed
  • Grand Theft Auto: Vice City Game Download For PC | Full Setup
  • SQL SHOW DATABASES Statement
  • Direct view storage Tube (DVST) in Computer Graphics
  • CRT Color Monitor in Computer Graphics

C++ Programs

  • More 300+ Examples
  • “Hello World” Program
  • Add Two Numbers
  • Area of Circle
  • Even or Odd Number
  • Find Factorial Number
  • Simple Calculator Program
  • Swap Two Numbers
  • Check Vowel and Consonant
  • Reverse a Number
  • Fibonacci Series
  • Leap Year
  • Toggle Characters
  • Check Super Digit
  • Check Anagram Strings
  • Spy Numbers
  • Check Automorphic Number
  • Check Neon Number
  • Check Pandigital Number
  • Strong Number
  • Inverse of Matrix

More C++ Examples…

  • Star(*) Pattern Programs
  • Wave Pattern Programs
  • Sorting Algorithms

Tutorials

  • C Tutorial

Copyright © 2019 - BeginnersBook.in - All Right Reserved || Sitemap