Computer Science, asked by monikak1791, 3 months ago

find factorial using for loop and use do while loop to choose operation as user want in c++

Answers

Answered by Berseria
7

Question :

To Find factorial of a number using for loop and

Answer :

Required Program in C++ :

In for loop ;

#include <iostream>

using namespace std;

int main ( )

{

int n, i, fact= 1 ;

cout <<"Enter Number to find the factorial : ";

cin>>n ;

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

fact = fact * i ;

cout <<" Factorial of " <<n<<" is "<< fact ;

}

Output :

Enter number to find the factorial : 6

Factorial of 6 is 720

Factorial :

Factorial Of a number, say N, represented by N! is the product of the first N natural numbers. For example factorial of 6 (6!) is calculated by 1×2×3×4×5×6 =720.

The Syntax of For loop :

for ( initialisation; test expression; update statement )

{

body of the loop ;

}

Similar questions