- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Binomial Coefficient in java
Binomial coefficient (c(n, r) or nCr) is calculated using the formula n!/r!*(n-r)!. Following is the Java program find out the binomial coefficient of given integers.
Program
import java.util.Scanner; public class BinomialCoefficient { public static long fact(int i) { if(i <= 1) { return 1; } return i * fact(i - 1); } public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter n value: "); int n = sc.nextInt(); System.out.println("Enter r value: "); int r = sc.nextInt(); long ncr = fact(n)/(fact(r)*fact(n-r)); System.out.println("c("+n+", "+r+") :"+ ncr); } }
Output
Enter n value: 8 Enter r value: 3 c(8, 3) :56
- Related Articles
- Binomial Coefficient in C++
- Maximum binomial coefficient term value in C
- How to find the binomial coefficient of two integers using JavaScript?
- Binomial Heap in C++?
- Binomial Distribution in Data Structures
- Binomial Random Variables in C++
- Binomial Heaps in Data Structure
- Negative Binomial distribution in Data Structures
- What Is Binomial Nomenclature?
- Memory representation of Binomial Heap in C++
- Expanding binomial expression using JavaScript
- Sum of squares of binomial coefficients in C++
- C program for Binomial Coefficients table
- Python Program to Implement Binomial Tree
- Find sum of even index binomial coefficients in C++

Advertisements