C PROGRAMMING Instructions: Edit the code below to meet the criteria of the following steps: Step 1) Enter the lengths of the sides directly into the structure using a structure pointer and the "->" operator. Step 2) Create a new function, and calculate the perimeter and area of the triangle within it. Pass the triangle structure to the function by reference using the structure pointer. Step 3) In the main( ) function, print the perimeter and area directly from the triangle structure to the console. Use the structure pointer and "->" operator in the call to printf( ). __________________________________________________________________________________________ #include #include #include struct calculate { float a, b, c, perimeter, area; }; int main() { struct calculate tri; printf("Enter Side Lengths of a Triangle: \n"); scanf("%f\n", &tri.a); scanf("%f\n", &tri.b); scanf("%f\n", &tri.c); tri.perimeter = (tri.a + tri.b + tri.c) / 2; tri.area = sqrt(tri.perimeter * (tri.perimeter - tri.a) * (tri.perimeter - tri.b) * (tri.perimeter - tri.c)); printf("Semiperimeter = %f\n", tri.perimeter); printf("Area = %f\n", tri.area); return 1; }
C PROGRAMMING
Instructions: Edit the code below to meet the criteria of the following steps:
Step 1) Enter the lengths of the sides directly into the structure using a structure pointer and the "->" operator.
Step 2) Create a new function, and calculate the perimeter and area of the triangle within it. Pass the triangle
structure to the function by reference using the structure pointer.
Step 3) In the main( ) function, print the perimeter and area directly from the triangle structure to the console.
Use the structure pointer and "->" operator in the call to printf( ).
__________________________________________________________________________________________
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct calculate
{
float a, b, c, perimeter, area;
};
int main()
{
struct calculate tri;
printf("Enter Side Lengths of a Triangle: \n");
scanf("%f\n", &tri.a);
scanf("%f\n", &tri.b);
scanf("%f\n", &tri.c);
tri.perimeter = (tri.a + tri.b + tri.c) / 2;
tri.area = sqrt(tri.perimeter * (tri.perimeter - tri.a) * (tri.perimeter - tri.b) * (tri.perimeter - tri.c));
printf("Semiperimeter = %f\n", tri.perimeter);
printf("Area = %f\n", tri.area);
return 1;
}
Step by step
Solved in 2 steps