Header Ads Widget

Write a C++ program to calculate the factorial of a number using loop

 

Write a C++ program to calculate the factorial of a number using loop

Given a number , write a program to find the factorial of a given numbers .

Sample input

4

Sample output:

24

 Write a C++ program to calculate the factorial of a number using loop

The objective of the code is to find the factorial of  number. Value of n is given by user .

Code(C++):-

#include <iostream>
using namespace std;
int main()
{
int i,n,fact=1;
cout<<"Enter the number ";
cin>>n;
for(i=1;i<=n;i++)
{
fact=fact*i;
}
cout<<"Factorial of a given number is "<<fact;
return(0);
}

output:-

Enter the number 4
Factorial of a given number is 24


Recommended Post :-

HCL Coding Questions:-

Capgemini Coding Questions:-

Companies interview:-

Full C course:-    

Key points:-

Cracking the coding interview:-

 Array and string:-

Tree and graph:-

Hackerearth Problems:-

Hackerrank Problems:-

Data structure:-

 MCQs:-