repl.it
C

Average of 3 triangles areas.

fork
loading
Files
  • main.c
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <stdio.h>

float b, h;
float a(b, h) {
    return 0.5 * b * h;
}

int main(void) {
    
    printf("Please enter information of 3 triangles.\n");

    float total = 0.0;

    int i = 0;
    while(i < 3) {
        
        float base, height;

        printf("Base: ");
        scanf("%f", &base);

        printf("Height: ");
        scanf("%f", &height);

        float area = a(base, height);

        total += area;

        i++;
    }

    printf("Average is:  %f.", total/3.0);

    return 0;
}
?