/* June 08, 1998 */ /* Program to compute the area of triangle or square */ #include #include /* function definition */ double area_triangle (double tbase, double theight); double area_square (double sside); main () { /* declarations */ double side, base, height; char type; /* Request for type */ printf("Enter S for Square or T for Triangle> "); scanf("%c", &type); if (type == 'T' || type == 't') { /* Get input */ printf("Input the length of the base of the triangle> "); scanf("%lf", &base); printf("Input the length of the height of the triangle> "); scanf("%lf", &height); /* display area of triangle */ printf("The area of the triangle is %.2f\n", area_triangle(base, height)); } else { /* Get input */ printf("Input the length of the side of the square> "); scanf("%lf", &side); /* display area of square */ printf("Area of the square is %.2f\n", area_square(side)); } } /* function definition */ double area_triangle(double tbase, double theight) { double tarea; /* compute area of triangle */ tarea = 0.5 * tbase * theight; return(tarea); } double area_square(double sside) { /* compute area of square */ double sarea; sarea = sside * sside; return(sarea); }