Given an integer N which denotes the points on the circumference of a circle, the task is to find the number of quadrilaterals formed using these points.
Examples:
Input: N = 5
Output: 5
Input: N = 10
Output: 210
Approach: The idea is to use permutation and combination to find the number of possible quadrilaterals using the N points on the circumference of the circle. The number of possible quadrilaterals will be
.
Below is the implementation of the above approach:
C++
// C++ implementation to find the// number of quadrilaterals formed// with N distinct points#include<bits/stdc++.h>using namespace std;// Function to find the factorial// of the given number Nint fact(int n){ int res = 1; // Loop to find the factorial // of the given number for(int i = 2; i < n + 1; i++) res = res * i; return res;}// Function to find the number of// combinations in the Nint nCr(int n, int r){ return (fact(n) / (fact(r) * fact(n - r)));}// Driver Codeint main(){ int n = 5; // Function Call cout << (nCr(n, 4));}// This code is contributed by rock_cool |
Java
// Java implementation to find the// number of quadrilaterals formed// with N distinct pointsclass GFG{ // Function to find the number of// combinations in the Nstatic int nCr(int n, int r){ return (fact(n) / (fact(r) * fact(n - r)));}// Function to find the factorial// of the given number Nstatic int fact(int n){ int res = 1; // Loop to find the factorial // of the given number for(int i = 2; i < n + 1; i++) res = res * i; return res;}// Driver Codepublic static void main(String[] args){ int n = 5; // Function Call System.out.println(nCr(n, 4));}}// This code is contributed by 29AjayKumar |
Python3
# Python3 implementation to find the# number of quadrilaterals formed# with N distinct points# Function to find the number of# combinations in the Ndef nCr(n, r): return (fact(n) / (fact(r) * fact(n - r)))# Function to find the factorial# of the given number Ndef fact(n): res = 1 # Loop to find the factorial # of the given number for i in range(2, n + 1): res = res * i return res# Driver Codeif __name__ == "__main__": n = 5 # Function Call print(int(nCr(n, 4))) |
C#
// C# implementation to find the// number of quadrilaterals formed// with N distinct pointsusing System;class GFG{ // Function to find the number of// combinations in the Nstatic int nCr(int n, int r){ return (fact(n) / (fact(r) * fact(n - r)));}// Function to find the factorial// of the given number Nstatic int fact(int n){ int res = 1; // Loop to find the factorial // of the given number for(int i = 2; i < n + 1; i++) res = res * i; return res;}// Driver Codepublic static void Main(String[] args){ int n = 5; // Function Call Console.Write(nCr(n, 4));}}// This code is contributed by shivanisinghss2110 |
Javascript
<script>// JavaScript implementation to find the// number of quadrilaterals formed// with N distinct points// Function to find the factorial// of the given number Nfunction fact(n){ let res = 1; // Loop to find the factorial // of the given number for(let i = 2; i < n + 1; i++) res = res * i; return res;}// Function to find the number of// combinations in the Nfunction nCr(n, r){ return (fact(n) / (fact(r) * fact(n - r)));}// Driver Code let n = 5; // Function Call document.write(nCr(n, 4));// This code is contributed by Surbhi Tyagi.</script> |
5
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
In case you wish to attend live classes with industry experts, please refer Geeks Classes Live


