public class Factorial {
public static void main(String[] args) {
int number = 15;
/*
* Factorial of any number is! n. For example, factorial of 4 is
* 4*3*2*1.
*/
int factorial = number;
for (int i = (number - 1); i > 1; i--) {
factorial = factorial * i;
}
System.out.println("Factorial of a number is "+number+"! = " + factorial);
}
}
OUTPUT:
Factorial of a number is 15! = 2004310016
No comments:
Post a Comment