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
6d9e9a36
Commit
6d9e9a36
authored
Dec 06, 2017
by
Dominik Widhalm
Browse files
Fixed comments in task 6.01
parent
6025fb41
Changes
1
Hide whitespace changes
Inline
Side-by-side
ch_6/task_01/main.c
View file @
6d9e9a36
...
...
@@ -61,19 +61,10 @@ double get_perimeter (struct triangle *trngl) {
* @return Area of the given triangle *
******************************************************************************/
double
get_area
(
struct
triangle
*
trngl
)
{
/*
First c
alculate
the height of the triangle
*/
/*
C
alculate
intermediate value for the height calculation
*/
double
s
=
get_perimeter
(
trngl
)
/
2
;
/* Calculate the actual area
using
the height (simplified) */
/* Calculate the actual area
via
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)!
*/
}
...
...
@@ -116,7 +107,7 @@ int main (void) {
/* Read in the user's input */
scanf
(
"%d"
,
&
my_trngl
.
b
);
/* Ask the user to enter the triangle's side c */
/* Ask the user to enter the triangle's side c
(must be the longest one)
*/
printf
(
"Please enter the integer length of side c: "
);
/* Read in the user's input */
scanf
(
"%d"
,
&
my_trngl
.
c
);
...
...
@@ -126,6 +117,8 @@ int main (void) {
/* Calculate the area */
area
=
get_area
(
&
my_trngl
);
printf
(
"Address of triangle: %p
\n
"
,(
void
*
)
&
my_trngl
);
/* Output the results */
printf
(
"
\n
The given triangle has a perimeter of %.2f
\n
"
,
perimeter
);
printf
(
" ... an area of %.2f
\n
"
,
area
);
...
...
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