Instructions) Edit the code in order to make the user enter the lengths of the sides of the triangle directly into the structure using a structure pointer and the "->" operator. Then, in a function, calculate the perimeter and area of the triangle. Pass the triangle structure to the function by reference using the structure pointer. Lastly, 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 - Edit the Code Below to Use Pointers
Instructions) Edit the code in order to make the user enter the lengths of the sides of the triangle directly into the structure using a structure pointer and the "->" operator. Then, in a function, calculate the perimeter and area of the triangle. Pass the triangle structure to the function by reference using the structure pointer. Lastly, 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 with 1 images