Factorial Program in C++ using Class Objects
Let us see the factorial problem with the help of classes and objects.
Factorial Program in C++ using Class Objects
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#include<iostream> using namespace std; class factorial { public: unsigned long long fact=1; int num; int input(); void fact_function(); void display(); }; int factorial::input() { cout<<"Please enter a number: "; cin>>num; } void 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() { factorial object; object.input(); object.fact_function(); object.display(); } |
Output
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