forked from 790hanu/Annex-qr-code-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateNCR.cs
48 lines (37 loc) · 918 Bytes
/
createNCR.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
class Ncr
{
static int CalculateFactorial(int num)
{
int fact = 1;
for (int i = 2; i <= num; i++)
{
fact = fact * i;
}
return fact;
}
static int CalculateNcr(int n, int r)
{
int ncr = 0;
int fact1 = 0;
int fact2 = 0;
int fact3 = 0;
fact1 = CalculateFactorial(n);
fact2 = CalculateFactorial(r);
fact3 = CalculateFactorial(n - r);
ncr = fact1 / (fact2*fact3);
return ncr;
}
static void Main(string[] args)
{
int ncr = 0;
int n = 0;
int r = 0;
Console.Write("Enter the value of 'n': ");
n = int.Parse(Console.ReadLine());
Console.Write("Enter the value of 'r': ");
r = int.Parse(Console.ReadLine());
ncr = CalculateNcr(n, r);
Console.WriteLine("Ncr: " + ncr);
}
}