Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

find factorial in c++ using class

#include <iostream>
using namespace std;

class Factorial
{
private:
    int num;
    int factorial = 1;

public:
    void calculateFactorial();
    void show();
};

void
Factorial::calculateFactorial()
{
    cout << "Enter a number : " << endl;
    cin >> num;

    if (num == 0 || num == 1)
    {
        factorial = 1;
    }
    else
    {
        while (num > 1)
        {
            factorial = factorial * num;
            num--;
        }
    }
}

void Factorial::show()
{
    cout << "Factorial : " << factorial << endl;
}

int main()
{
    Factorial factorial;
    factorial.calculateFactorial();
    factorial.show();
}
Source by www.codevscolor.com #
 
PREVIOUS NEXT
Tagged: #find #factorial #class
ADD COMMENT
Topic
Name
9+5 =