Advertisement
Guest User

factorial

a guest
Sep 18th, 2014
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. //Gerardo Morales
  2. // Factorial de in numero
  3. #include <iostream>
  4. using namespace std;
  5. //Variables
  6. int n,f; //N numero que te dan y F factorial
  7. int main ()
  8. {
  9. //Pedir el numero que quieres el factorial
  10. cout<<"Cual numero quieres?";
  11. cin>>n;
  12.  
  13. //Checar si n es 1 o 0
  14. if(n==1 || n==0)
  15. cout<<n<<"! = 1"<<endl;
  16. else
  17. {
  18. cout<<n<<"! = ";
  19.  
  20. for(fact=1,f=n; f>0; f--)
  21. {
  22. fact = fact * f;
  23. }
  24. if ( f==1)
  25. cout<<f<<" * ";
  26. else
  27. cout<<f<<" * ";
  28. } // for
  29. cout<<fact<<endl;
  30. }//else
  31. } //main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement