In mathematics, the factorial of a non-negative integer n, denoted by n!, is the product of all positive integers less than or equal to n. For example,
5! = 5 * 4 * 3 * 2 * 1 = 120.
The value of 0! is 1, according to the convention for an empty product.
The factorial operation is encountered in many areas of mathematics, notably in combinatorics, algebra, and mathematical analysis. Its most basic occurrence is the fact that there are n! ways to arrange n distinct objects into a sequence (i.e., permutations of the set of objects). This fact was known at least as early as the 12th century, to Indian scholars. Fabian Stedman in 1677 described factorials as applied to change ringing.
Information source: wikipedia.org
Program:->
Output |
import java.util.Scanner;
public class SeFact {
public static void main(String[] args) {
int x, f = 1;
System.out.print("Enter a number: ");
Scanner sc = new Scanner(System.in);
x = sc.nextInt();
for (int i = 1; i <= x; ++i) {
f = f * i;
}
System.out.println("Factorial: " + f);
}
}
Note: The program must be saved with name "SeFact.java"
0 comments :
Post a Comment