#include<iostream.h>
void main()
{
int i,n,fact=1;
cout<<"Enter a number : ";
cin>>n;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
cout<<"Factorial of "<<n<<" is "<<fact<<endl;
}
OUTPUT ---
Enter a number : 0
Factorial of 0 is 1
[Program finished]
Enter a number : 1
Factorial of 1 is 1
[Program finished]
Enter a number : 2
Factorial of 2 is 2
[Program finished]
Enter a number : 3
Factorial of 3 is 6
[Program finished]
Enter a number : 4
Factorial of 4 is 24
[Program finished]
Enter a number : 5
Factorial of 5 is 120
[Program finished]
Enter a number : 6
Factorial of 6 is 720
[Program finished]
Enter a number : 7
Factorial of 7 is 5040
[Program finished]
Enter a number : 8
Factorial of 8 is 40320
[Program finished]
Enter a number : 9
Factorial of 9 is 362880
[Program finished]
Enter a number : 10
Factorial of 10 is 3628800
[Program finished]
Post a Comment