Commit 6d9e9a36 authored by Dominik Widhalm's avatar Dominik Widhalm
Browse files

Fixed comments in task 6.01

parent 6025fb41
......@@ -61,19 +61,10 @@ double get_perimeter (struct triangle *trngl) {
* @return Area of the given triangle *
******************************************************************************/
double get_area (struct triangle *trngl) {
/* First calculate the height of the triangle */
/* Calculate 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("\nThe given triangle has a perimeter of %.2f\n",perimeter);
printf(" ... an area of %.2f\n",area);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment