-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.c
75 lines (73 loc) · 2.23 KB
/
script.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
63
64
65
66
67
68
69
70
71
72
73
74
75
#include <stdio.h>;
/*
-------------------------------------------------------------------------
| Author => Ibrahim Elkhalil Benyahia |
| DZ Developement Comunity |
| |
| its programme to claculate composition with C programming language |
| written with methode to be simple and easy to read to help every body |
| looking for this kinde of logics peace .... |
-------------------------------------------------------------------------
*/
// factoriale function declaration
long factorial(long x);
// composition function declaration
long composition(long n, long p);
// main function
int main(void)
{
// defining variable nedded in main fuction
int run = 0;
long n;
long p;
// logic to make the programme end by typing 1
while (run != 1)
{
// taking n value from user
printf("enter the n value=> ");
scanf("%d", &n);
// taking p value from user
printf("enter the p value=> ");
scanf("%d", &p);
// condition for composition law
if (n >= p)
{
long x = composition(n, p);
printf("the result is => %ld", x);
}
// error of composition law
else if (n < p)
{
printf("\nsorry make sure tha n >= p");
}
// asking user for ending programme or not 1 to end it or 0 to continue
printf("\nif you want to end the programme type 1 (type 0 to start again) => ");
scanf("%d", &run);
// ending the programme
if (run == 1){
printf("programme ended");
return 0;
}
// main code end
}
}
// factoriale function logic
long factorial(long x)
{
long result = 1;
if (x > 0)
{
for (x; x > 1; x -= 1)
{
result *= x;
}
}
return result;
}
// composition function declaration
long composition(long n, long p)
{
long z = n - p;
long result = factorial(n) / (factorial(p) * factorial(z));
return result;
}