Answer to Question #169503 in C++ for Amanuel futessa

Question #169503

Take an integer from the user and display the factorial of that number


1
Expert's answer
2021-03-07T18:42:13-0500

#include <iostream>

using namespace std;

int main() 

{

   int n;

   unsigned long long int fact=1;

   cout<<"Enter a positive integer ";

   cin>>n;

   if(n<0)

   {

       cout<<"\nError! Negative Integer entered. ";

   }

   else

   {

       for(int i=1;i<=n;i++)

       {

           fact=fact*i;

       }

   cout<<"\nFactorial of "<<n<<" is "<<fact;

}

return 0;

}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS