How to calculate the area of a pentagon in C

2 Answers

0 votes
#include <stdio.h>

float pentagon_area(float side, float apothem) {
    return 5.0f * (side * apothem) / 2.0f;
}

int main(void) {
    float side = 5.0f;
    float apothem = 3.0f;

    float area = pentagon_area(side, apothem);

    printf("Area = %.2f\n", area);

    return 0;
}



/*
run:

Area = 37.50

*/

 



answered Jul 12, 2021 by avibootz
edited 6 hours ago by avibootz
0 votes
#include <stdio.h>
#include <math.h>

double area_regular_pentagon(double side) {
    return (1.0 / 4.0) * sqrt(5.0 * (5.0 + 2.0 * sqrt(5.0))) * pow(side, 2);
}

int main(void) {
    printf("%f\n", area_regular_pentagon(7.0));
    
    return 0;
}


/*
run:

84.303393

*/

 



answered 1 hour ago by avibootz
edited 1 hour ago by avibootz
...