Monday, 7 December 2020

Factorial of Number using While Loop

import java.util.*;
public class FactorialWhile 
{
	public static void main(String[] args) 
	{
		Scanner s = new Scanner(System.in);
		System.out.println("\n Enter Number...");
		int number = s.nextInt();
		int fact=1,i=1;
			while(i<=number)
			{
				fact=fact*i;
				i++;
			}
	System.out.println("\n Factorial of "+number+" is = "+fact);
	}
}

Output:
Enter Number...
7

 Factorial of 7 is = 5040
 

No comments:

Post a Comment

If you have any doubts, please let me know

Pattern 31 & 32