Computer Science, asked by vishwaneraj8988, 10 months ago

Write a program to find the factorial of a given number using while loop.

Answers

Answered by amannishad0512p5zxh6
2

class factorial

{

public static void main( int n)

{

int fact=1;

while(n!=0)

{

fact+=fact×n;

n- -;

}

System.out.println("Factorial is "+fact);

}

}

Follow me for more doubts.

Mark me brainlest if you like my answer.

Answered by stylishtamilachee
3

Answer:

public class Calculate

{

public void factorial (long num)

{

long i = 0, fact = 1 ;

i = num ;

while ( i != 0 )

{

fact = fact * i ;

--i ;

}

System.out.println("The factorial of " + num + "is" + fact) ;

}

}

Example output:

The factorial of 5 is 120

The while loop :

The second loop available in java is the while loop.

The while loop is an entry controlled loop.

Where the loop-body may contain a single statement, a compound statement or an empty statement.

The loop iterates while the expression evaluates to true when the expression becomes false, the program control passes to the line after the loop body code.

Similar questions