fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int factorial (int num1) //counts the factiorial
  5. {
  6. if (num1==0)
  7. {
  8. return 1;
  9. //cout << "The factiorial given number "<<num1<< " is: "<<factorial<<endl;
  10. }
  11. else
  12. {
  13. //result = 1;
  14. //factorial = 1;
  15. //for (i = 1; i <= num1; i++)
  16. return num1 * factorial(num1 - 1);
  17. //cout << "The factiorial given number "<<num1<< " is: "<<result<<endl;
  18. }
  19. }
  20.  
  21. int main()
  22. {
  23. int num1 =5;
  24. cout << "Enter the number ";
  25. cin >> num1; // wczytujemy liczbę
  26. cout << "The given numer is : " <<num1 <<endl;
  27.  
  28. if (num1 >= 0) // factorial conditions, number must be positive (+)
  29. {
  30. //cout << "The given number is positive I will count the factiorial ;)"<<endl;
  31. cout << "The given number "<<num1<<" is positive I will count the factiorial ;)"<<endl;
  32. }
  33. else
  34. {
  35. //cout << "The given number is negative I will not count the factiorial ;("<<endl;
  36. cout << "The given number "<<num1<<" is negative I will not count the factiorial ;("<<endl;
  37. }
  38. //cout << "The factiorial given number "<<num1<< " ! is: "<<factorial(mum1)<<endl;
  39. cout << "The "<<num1<<"! factiorial is: "<<factorial(num1)<<endl;
  40. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Enter the number The given numer is : 5
The given number 5 is positive I will count the factiorial ;)
The 5! factiorial is: 120