Take an integer from the user and display the factorial of that number
#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;
}
Comments
Leave a comment