Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
matjul
/
iax0583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
8def9a56
authored
Dec 03, 2018
by
matjul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
bdcb7388
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
129 additions
and
0 deletions
lab12bonustask.c
lab12bonustask.c
0 → 100644
View file @
8def9a56
#include <stdio.h>
#include <math.h>
#include <string.h>
void
meanPoint
(
float
matrix
[
5
][
3
],
float
lenghts
[
3
]);
void
fromPointsToMean
(
float
matrix
[
5
][
3
],
float
lenghts
[
3
],
float
leng
[
5
][
3
]);
void
Distance
(
float
leng
[
5
][
3
],
float
distances
[
5
]);
void
bubbleSort
(
float
distances
[
5
],
int
index
[
5
]);
int
main
(){
float
matrix
[
5
][
3
]
=
{
{
1
,
3
.
1
,
21
},
{
2
,
-
3
.
2
,
23
},
{
2
.
3
,
12
.
8
,
2
},
{
2
,
1
.
4
,
-
23
},
{
12
,
2
,
-
2
.
3
}
};
int
i
,
j
;
float
lenghts
[
3
]
=
{
0
};
float
leng
[
5
][
3
];
float
distances
[
5
]
=
{
0
};
int
var
;
int
index
[
5
];
for
(
i
=
0
;
i
<
5
;
i
++
){
index
[
i
]
=
i
;
}
meanPoint
(
matrix
,
lenghts
);
printf
(
"The mean of point of this crap is: "
);
for
(
j
=
0
;
j
<
3
;
j
++
){
printf
(
"%f, "
,
lenghts
[
j
]);
}
printf
(
"
\n
"
);
fromPointsToMean
(
matrix
,
lenghts
,
leng
);
printf
(
"the point from mean:
\n
"
);
for
(
i
=
0
;
i
<
5
;
i
++
){
for
(
j
=
0
;
j
<
3
;
j
++
){
printf
(
"%f, "
,
leng
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
printf
(
"
\n
The distaces from mean point to the other point lol:
\n
"
);
Distance
(
leng
,
distances
);
for
(
i
=
0
;
i
<
5
;
i
++
){
printf
(
"%f
\n
"
,
distances
[
i
]);
}
printf
(
"
\n
The same distaces but in order lol:
\n
"
);
bubbleSort
(
distances
,
index
);
for
(
i
=
0
;
i
<
5
;
i
++
){
var
=
index
[
i
];
for
(
j
=
0
;
j
<
3
;
j
++
){
printf
(
"%f "
,
matrix
[
var
][
j
]);
}
printf
(
"
\n
"
);
}
return
0
;
}
void
meanPoint
(
float
matrix
[
5
][
3
],
float
lenghts
[
3
]){
int
i
,
j
;
float
len
[
3
]
=
{
0
};
for
(
j
=
0
;
j
<
3
;
j
++
){
for
(
i
=
0
;
i
<
5
;
i
++
){
len
[
j
]
+=
matrix
[
i
][
j
];
}
lenghts
[
j
]
=
len
[
j
]
/
5
;
}
}
void
fromPointsToMean
(
float
matrix
[
5
][
3
],
float
lenghts
[
3
],
float
leng
[
5
][
3
]){
int
i
,
j
;
for
(
i
=
0
;
i
<
5
;
i
++
){
for
(
j
=
0
;
j
<
3
;
j
++
){
leng
[
i
][
j
]
=
matrix
[
i
][
j
]
-
lenghts
[
j
];
}
}
}
void
Distance
(
float
leng
[
5
][
3
],
float
distances
[
5
]){
int
i
,
j
;
int
x
=
0
;
float
sumOfSquares
=
0
;
for
(
i
=
0
;
i
<
5
;
i
++
){
for
(
j
=
0
;
j
<
3
;
j
++
){
sumOfSquares
+=
pow
(
leng
[
i
][
j
],
2
);
}
distances
[
x
]
=
sqrt
(
sumOfSquares
);
x
++
;
sumOfSquares
=
0
;
}
}
void
bubbleSort
(
float
distances
[
5
],
int
index
[
5
]){
int
i
,
j
,
tmp
,
swap
;
for
(
i
=
0
;
i
<
5
;
i
++
){
for
(
j
=
i
+
1
;
j
<
5
;
j
++
){
if
(
distances
[
i
]
>
distances
[
j
]){
tmp
=
distances
[
i
];
distances
[
i
]
=
distances
[
j
];
distances
[
j
]
=
tmp
;
swap
=
index
[
i
];
index
[
i
]
=
index
[
j
];
index
[
j
]
=
swap
;
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment