write a program to find the print the factorial of the number 8
Answers
Answer:
Factorial of a positive integer n is the product of all values from n to 1. For example, the factorial of 3 is (3 * 2 * 1 = 6).
Algorithm
1. Take integer variable A
2. Assign a value to the variable
3. From value, A up to 1 multiply each digit and store
4. The final stored value is factorial of A
Example
import java.util.Scanner;
public class Factorial {
public static void main(String args[]){
int i, factorial=1, number;
System.out.println("Enter the number to which you need to find the factorial:");
Scanner sc = new Scanner(System.in);
number = sc.nextInt();
for(i = 1; i<=number; i++) {
factorial = factorial * i;
}
System.out.println("Factorial of the given number is:: "+factorial);
}
}
Output
Enter the number to which you need to find the factorial:
25
Factorial of the given number is:: 2076180480Factorial of a positive integer n is the product of all values from n to 1. For example, the factorial of 3 is (3 * 2 * 1 = 6).
Algorithm
1. Take integer variable A
2. Assign a value to the variable
3. From value, A up to 1 multiply each digit and store
4. The final stored value is factorial of A
Example
import java.util.Scanner;
public class Factorial {
public static void main(String args[]){
int i, factorial=1, number;
System.out.println("Enter the number to which you need to find the factorial:");
Scanner sc = new Scanner(System.in);
number = sc.nextInt();
for(i = 1; i<=number; i++) {
factorial = factorial * i;
}
System.out.println("Factorial of the given number is:: "+factorial);
}
}
Output
Enter the number to which you need to find the factorial:
25
Factorial of the given number is:: 2076180480
Explanation:
Explanation:
The factorial of n is denoted by n! and calculated by the product of integer numbers from 1 to n.
For n>0,
n! = 1×2×3×4×...×n
For n=0,
0! = 1