Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Gerardo Morales
- // Factorial de in numero
- #include <iostream>
- using namespace std;
- //Variables
- int n,f; //N numero que te dan y F factorial
- int main ()
- {
- //Pedir el numero que quieres el factorial
- cout<<"Cual numero quieres?";
- cin>>n;
- //Checar si n es 1 o 0
- if(n==1 || n==0)
- cout<<n<<"! = 1"<<endl;
- else
- {
- cout<<n<<"! = ";
- for(fact=1,f=n; f>0; f--)
- {
- fact = fact * f;
- }
- if ( f==1)
- cout<<f<<" * ";
- else
- cout<<f<<" * ";
- } // for
- cout<<fact<<endl;
- }//else
- } //main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement