Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int factorial(int);
- int main() {
- int again = 1;
- do {
- int n, fact;
- cout << "Enter a positive number to find factorial : ";
- cin >> n;
- while (n <= 0) {
- cout << "\nError : You entered a negative number." << endl;
- cout << "\nPlease enter a positive number to find factorial : ";
- cin >> n;
- }
- fact = factorial(n);
- cout << "\nNumber" << setw(14) <<"Factorial" << endl;
- cout << n << setw(13) << fact << endl;
- cout << "\nDo you want to repeat the program? (1 = Yes, 0 = No)" << endl;
- cin >> again;
- }
- while (again == 1);
- return 0;
- }
- int factorial(int f) {
- int fact = 1;
- for (int i = 1; i<=f; i++) {
- fact*=i;
- }
- return fact;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement