answer in java please (serious answers only)
Attachments:
Answers
Answered by
0
Explanation:
Write a function fact(int n) to find the factorial of a number n. Include a main class to find the value of S where:
S = n! / (m!(n - m)!)
where, n! = 1 x 2 x 3 x ………. x n
Java
User Defined Methods
ANSWER
import java.util.Scanner; public class KboatFactorial { public long fact(int n) { long f = 1; for (int i = 1; i <= n; i++) { f *= i; } return f; } public static void main(String args[]) { KboatFactorial obj = new KboatFactorial(); Scanner in = new Scanner(System.in); System.out.print("Enter m: "); int m = in.nextInt(); System.out.print("Enter n: "); int n = in.nextInt(); double s = (double)(obj.fact(n)) / (obj.fact(m) * obj.fact(n - m)); System.out.println("S=" + s); } }
Similar questions