Let us see the C++ program for finding the factorial of a number using the single inheritance.
C++ program for factorial using single inheritance
#include<iostream> using namespace std; //main class class factorial { public: unsigned long long fact=1; int num; void display(); }; //child class class child_factorial: public factorial { public: int input(); void fact_function(); }; int child_factorial::input() { cout<<"Please enter a number: "; cin>>num; } void child_factorial::fact_function() { for(int i=1;i<=num;i++) { fact=fact*i; } } void factorial::display() { cout<<"Factorial of entered number is: "<<fact; } int main() { child_factorial object; object.input(); object.fact_function(); object.display(); }
More Practice on Factorial problem in C++
- Factorial Program in C++
- factorial using single inheritance
- Factorial Program in C++ using Class Objects
- factorial using Multiple inheritances
-
C++ program for factorial using Constructor DestructorFactorial Of A Number By Using The Recursion - Factorial Program with structures and pointers C++
- Factorial Program with Nested Structure C++
- factorial of a no. by defining the member functions outside the class