Factorial in C++.

Factorial: factorial is the product of all integers less than or equal tonbut greater than or equal to 1. The factorial value of 0 is defined as equal to 1. The factorial values for negative integers are not defined.

 

 

Let’s write the following code to find Factorial of any number.

 

 

Step 1: Let’s open turbo C++ and write the following code.

 

//Code

 

// Add preproceesor

 

#include<conio.h>

#include<iostream.h>

void main()

{

long int i=1,fact=1,n;

//Clear Screen

clrscr();

cout<<”enter any number:”;

cin>>n;

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

{

fact=fact*i;

}

cout<<”Factorial := “<<fact;

getch();

}

 

 

Step 2: Run the program and see Output.

 

 

Output:

 

fact-output

 

Happy Coding.

 

 

 

Tags: , , ,