-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASSN3.C
62 lines (61 loc) · 970 Bytes
/
ASSN3.C
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//to calculate nCr
#include<conio.h>
#include<stdio.h>
#define GR textcolor(LIGHTGRAY);
#define CY textcolor(CYAN);
long double fact(int n);
void main()
{
int n,r,c;
long double nf,nrf,nr;
while(1)
{
clrscr();
gotoxy(5,5);
GR;
cprintf("enter the value of 'n' :");
CY;
fflush(stdin);
cscanf("%d",&n);
gotoxy(5,7);
GR;
cprintf("enter the value of 'r' :");
CY;
fflush(stdin);
cscanf("%d",&r);
if(n<0 || n<r || r<0 ||r==966)
{
gotoxy(5,6);
textcolor(RED);
cprintf("Invalid input ,please enter them properly.");
//printf(" %d %c",r,r);
n=0;
r=0;
}
nf=fact(n);
nr=fact(r);
nrf=fact(n-r);
gotoxy(5,9);
cprintf(" the result is %.2Lf ",nf/(nr*nrf));
fflush(stdin);
gotoxy(5,15);
printf("press any key and hit enter to continue or hit enter to QUIT ....");
//getch();
while(!kbhit());
c=getchar();
if(c==10)
exit();
else
continue;
}
}
long double fact(int n)
{
long double temp=1.0;
while(n>0)
{
temp=temp*n;
n--;
}
return(temp);
}