fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Fact {
  5. int n;
  6.  
  7. public:
  8. void getdata(int x) {
  9. n = x;
  10. }
  11.  
  12. int facto() {
  13. int f = 1;
  14. for (int i = n; i >= 1; i--) {
  15. f = f * i;
  16. }
  17. return f;
  18. }
  19. };
  20.  
  21. int main() {
  22. int P;
  23. cout << "Enter any number: ";
  24. cin >> P;
  25.  
  26. Fact obj1;
  27. obj1.getdata(P);
  28.  
  29. int q = obj1.facto();
  30. cout << "The factorial is " << q << endl;
  31.  
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.01s 5308KB
stdin
Standard input is empty
stdout
Enter any number: The factorial is 0