Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
chazog
/
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
c493bd4c
authored
Dec 16, 2018
by
chazog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
53d6d295
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
110 additions
and
0 deletions
Lab12/Task1.c
Lab12/Task1.c
0 → 100644
View file @
c493bd4c
#include <stdio.h>
#include <math.h>
#define NoOfDimensions 2
void
distancesf
(
float
points
[
5
][
3
],
float
distances
[
10
]);
void
MeanPointf
(
float
points
[
5
][
3
],
float
MeanPoint
[
3
]);
float
AvgDist
(
float
points
[
5
][
3
],
float
MeanPoint
[
3
],
float
MeanDist
[
5
],
int
PointNumber
[
5
]);
int
main
()
{
int
i
,
j
,
swap
,
PointNumber
[
5
];
float
MeanPoint
[
3
];
float
MeanDist
[
5
];
float
points
[
5
][
3
]
=
{{
1
,
3
.
1
,
2
.
1
},
{
2
,
-
3
.
2
,
23
},
{
2
.
3
,
12
.
8
,
2
},
{
2
,
1
.
4
,
-
23
},
{
12
,
2
,
-
2
.
3
}};
float
distances
[
10
];
distancesf
(
points
,
distances
);
for
(
i
=
0
;
i
<
10
;
i
++
)
{
printf
(
"%.2f
\n
"
,
distances
[
i
]);
}
float
MinDist
=
distances
[
0
];
for
(
i
=
1
;
i
<
10
;
i
++
)
{
if
(
distances
[
i
]
<
MinDist
)
{
MinDist
=
distances
[
i
];
}
}
MeanPointf
(
points
,
MeanPoint
);
printf
(
"Min Dist is :
\t
%.2f"
,
MinDist
);
printf
(
"
\n
Mean point is:
\t
"
);
for
(
i
=
0
;
i
<
3
;
i
++
)
{
printf
(
"%.2f "
,
MeanPoint
[
i
]);
}
printf
(
"
\n
Average distance to mean point is:
\t
%.2f
\n
"
,
AvgDist
(
points
,
MeanPoint
,
MeanDist
,
PointNumber
));
for
(
i
=
0
;
i
<
5
;
i
++
)
{
for
(
j
=
0
;
j
<
4
;
j
++
)
{
if
(
MeanDist
[
j
]
>
MeanDist
[
j
+
1
])
{
swap
=
MeanDist
[
j
];
MeanDist
[
j
]
=
MeanDist
[
j
+
1
];
MeanDist
[
j
+
1
]
=
swap
;
}
}
}
printf
(
"from lowest to biggest distance to the mean point:
\n
"
);
for
(
i
=
0
;
i
<
5
;
i
++
)
{
printf
(
"point %d:
\t
%.2f
\n
"
,
PointNumber
[
i
],
MeanDist
[
i
]);
}
}
void
distancesf
(
float
points
[
5
][
3
],
float
distances
[
10
])
{
int
N
=
0
;
int
k
=
0
;
int
i
,
j
,
h
;
float
x
=
0
;
for
(
j
=
0
;
j
<
5
;
j
++
)
{
N
++
;
for
(
i
=
N
;
i
<
5
;
i
++
)
{
for
(
h
=
0
;
h
<
NoOfDimensions
;
h
++
)
{
x
+=
pow
((
points
[
i
][
h
]
-
points
[
j
][
h
]),
2
);
}
distances
[
k
]
=
pow
(
x
,
0
.
5
);
k
++
;
}
}
}
void
MeanPointf
(
float
points
[
5
][
3
],
float
MeanPoint
[
3
])
{
int
i
;
float
SumX
=
0
,
SumY
=
0
,
SumZ
=
0
;
for
(
i
=
0
;
i
<
5
;
i
++
)
{
SumX
+=
points
[
i
][
0
];
SumY
+=
points
[
i
][
1
];
SumZ
+=
points
[
i
][
2
];
}
MeanPoint
[
0
]
=
(
SumX
/
5
);
MeanPoint
[
1
]
=
(
SumY
/
5
);
MeanPoint
[
2
]
=
(
SumY
/
5
);
}
float
AvgDist
(
float
points
[
5
][
3
],
float
MeanPoint
[
3
],
float
MeanDist
[
5
],
int
PointNumber
[
5
])
{
float
answer
;
float
SumDist
=
0
;
int
i
;
for
(
i
=
0
;
i
<
5
;
i
++
)
{
MeanDist
[
i
]
=
pow
((
pow
(
MeanPoint
[
0
]
-
points
[
i
][
0
],
2
)
+
pow
(
MeanPoint
[
1
]
-
points
[
i
][
1
],
2
)
+
pow
(
MeanPoint
[
1
]
-
points
[
i
][
2
],
2
)),
0
.
5
);
SumDist
+=
MeanDist
[
i
];
PointNumber
[
i
]
=
(
i
+
1
);
}
answer
=
(
SumDist
/
5
);
return
answer
;
}
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