-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathzad17_ms.c
58 lines (51 loc) · 1.34 KB
/
zad17_ms.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
#include <stdio.h>
#include <stdlib.h>
struct ciag
{
int dl;
double *el;
struct ciag* innerSet;
};
struct ciag* calcDifferentialSet(double *t, int n)
{
int setLength = n - 1;
double *setBody = (double *)malloc((unsigned)setLength * sizeof(double));
for (int i = 1; i < n; i++)
{
setBody[i - 1] = t[i] - t[i - 1];
}
struct ciag* differentialSet = malloc(sizeof(int) + sizeof(double*)) + sizeof(struct ciag*));
differentialSet->dl = setLength;
differentialSet->el = setBody;
if (differentialSet->dl > 0)
{
differentialSet->innerSet = calcDifferentialSet(differentialSet->el, differentialSet->dl);
}
return differentialSet;
}
void print_i(double t[], int n)
{
for (int i = 0; i < n - 1; i++)
{
printf("%lf, ", t[i]);
}
printf("%lf", t[n-1]);
}
int main()
{
int n;
if(!scanf("%d", &n)) printf("wrong input");
double *t = (double *)malloc((unsigned)n * sizeof(double));
for (int i = 0; i < n; i++)
{
if(!scanf("%lf", &t[i])) printf("wrong input");
}
struct ciag* differentialSet = calcDifferentialSet(t, n);
do
{
printf("%d (", differentialSet->dl);
print_i(differentialSet->el, differentialSet->dl);
printf(")\n");
differentialSet = differentialSet->innerSet;
}while(differentialSet->dl>0);
}