This repository has been archived by the owner on Aug 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
library.c
83 lines (70 loc) · 1.73 KB
/
library.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
76
77
78
79
80
81
82
83
#include "library.h"
#include <stdio.h>
#include <stdlib.h>
// Calcul du PGCD
int gcd(int a, int b) {
int t;
if(b == 0) {
return -1;
}
do {
if (a < b)
{
t = a;
a = b;
b = t;
}
a = a - b;
} while (a);
return b;
}
// Comparaison de deux entiers
int compare(int a, int b) {
int result = 0;
if(a < b )
result = -1;
else if(a > b)
result = 1;
return result;
}
// Somme des n premiers entiers
int sumNPrimeInts(int n) {
int sum = 0;
for(; n > 0 ; n--) {
sum += n;
}
return sum;
}
// Comparaison de deux flottants
// Simplification
Fraction simplificate(Fraction frac) {
int numHigherDivider = frac.numerator;
int denHigherDivider = frac.denominator;
int sizeOfNumDividers = numHigherDivider;
int sizeOfDemDividers = denHigherDivider;
int *numDividers = calloc(sizeOfNumDividers, sizeof(int));
int *denDividers = calloc(sizeOfDemDividers, sizeof(int));
int n = 0;
for(int i = numHigherDivider ; i > 0 ; i--) {
if(frac.numerator%i == 0) {
numDividers[n] = i;
n++;
}
}
n = 0;
for(int i = denHigherDivider ; i > 0 ; i--) {
if(frac.denominator%i == 0) {
denDividers[n] = i;
n++;
}
}
for(int i = sizeOfNumDividers ; i >= 0 ; i--) {
for(int j = sizeOfDemDividers ; i >= 0 ; i--) {
int numeratorDivider = numDividers[i];
int denominatorDivider = denDividers[j];
if(numeratorDivider == denominatorDivider) {
Fraction result = {frac.numerator/numeratorDivider, frac.denominator/denominatorDivider};
}
}
}
}