Write a program to find the factorial of a number in C++ - codeswithmrinal
#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 : 0Factorial of 0 is 1[Program finished]Enter a number : 1Factorial of 1 is 1[Program finished]Enter a number : 2Factorial of 2 is 2[Program finished]Enter a number : 3Factorial of 3 is 6[Program finished]Enter a number : 4Factorial of 4 is 24[Program finished]Enter a number : 5Factorial of 5 is 120[Program finished]Enter a number : 6Factorial of 6 is 720[Program finished]Enter a number : 7Factorial of 7 is 5040[Program finished]Enter a number : 8Factorial of 8 is 40320[Program finished]Enter a number : 9Factorial of 9 is 362880[Program finished]Enter a number : 10Factorial of 10 is 3628800[Program finished]
Post a Comment