Created
February 5, 2016 00:22
-
-
Save batmantec/9807d28cc44bf5790465 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main(){ | |
int n,count,product,sum,fac; | |
char answ; | |
cout<<"This program calculate the factorial of a number."<<endl; | |
do { | |
cout <<"Please type an positive number: "; | |
cin >> n; | |
count=1; | |
product=1; | |
sum=1; | |
if (n>1) { | |
do{ | |
count++; | |
product=product*(sum+1); | |
sum++; | |
fac=product; | |
}while (count!=n); | |
cout <<"The factorial of "<<n<<" is: "<<fac<<endl; | |
cout <<"Would you like to type another number (y/n)?"; | |
cin >> answ; | |
} else { | |
if (n==1) { | |
cout <<"The factorial of 1 is: 1"<<endl; | |
cout <<"Would you like to type another number (y/n)?"<<endl; | |
cin>>answ; | |
} else { | |
cout<<"The number that you enter was negative, please try again."<<endl; | |
answ='y'; | |
} | |
} | |
} while(answ=='y'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment