Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
master-embedded-systems
c-exercise-solutions public
Commits
6025fb41
Commit
6025fb41
authored
Dec 05, 2017
by
Dominik Widhalm
Browse files
Improved example solution for task 6.01 (thanks to FG)
parent
5c7fb6b8
Changes
1
Hide whitespace changes
Inline
Side-by-side
ch_6/task_01/main.c
View file @
6025fb41
...
...
@@ -63,9 +63,17 @@ double get_perimeter (struct triangle *trngl) {
double
get_area
(
struct
triangle
*
trngl
)
{
/* First calculate the height of the triangle */
double
s
=
get_perimeter
(
trngl
)
/
2
;
double
h_c
=
(
2
.
0
/
trngl
->
c
)
*
sqrt
(
s
*
(
s
-
trngl
->
a
)
*
(
s
-
trngl
->
b
)
*
(
s
-
trngl
->
c
));
/* Calculate the actual area using the height */
return
((
trngl
->
c
*
h_c
)
/
2
.
0
);
/* Calculate the actual area using the height (simplified) */
return
sqrt
(
s
*
(
s
-
trngl
->
a
)
*
(
s
-
trngl
->
b
)
*
(
s
-
trngl
->
c
));
/* The calculation above is a simplified combination of the calculation of
* the height of the side c (h_c) and the area calculation based on h_c.
*
* double h_c = (2.0 / trngl->c) * sqrt(s * (s-trngl->a) * (s-trngl->b) * (s-trngl->c));
* double area = (trngl->c * h_c) / 2.0;
*
* If you use the equation for h_c in the equation for area, you can cross
* out (2.0 / trngl->c) with (trngl->c / 2.0)!
*/
}
...
...
Write
Preview
Supports
Markdown
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