Skip to content

Commit

Permalink
Binomial Coefficient Calculator
Browse files Browse the repository at this point in the history
This Java program calculates and prints a term from the binomial expansion using user-provided values for the binomial coefficients and powers. It takes four inputs: two numbers for the binomial coefficient, and two powers, then computes and displays the specified term.
  • Loading branch information
Priyanshu-2811 authored May 28, 2024
1 parent 781d317 commit ea00ed2
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Bino.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import java.util.Scanner;

class Bino {
int p, m, e, w;
int comb;
Scanner sc = new Scanner(System.in);

Bino() {
p = 0;
m = 0;
}

void input() {
System.out.println("Enter the first number (p): ");
p = sc.nextInt();
System.out.println("Enter the second number (m): ");
m = sc.nextInt();
System.out.println("Enter the highest power (w): ");
w = sc.nextInt();
System.out.println("Enter the lowest power (e): ");
e = sc.nextInt();
}

int fact(int x) {
int s = 1;
for (int i = 1; i <= x; i++) {
s = s * i;
}
return s;
}

int compute() {
int a = fact(p);
int b = fact(m);
int k = fact(p - m);
comb = a / (b * k);
return comb;
}

void bmial() {
int d = compute();
System.out.print(d + " * " + Math.pow(p, w) + " * " + Math.pow(m, e));
w--;
e++;
}

public static void main(String[] args) {
Bino ob = new Bino();
ob.input();
ob.bmial();
}
}

0 comments on commit ea00ed2

Please sign in to comment.