#include #include "prog04header.h" int main() { Triangle tri1, tri2; double area1, area2; XY centroid1, centroid2; /* 1つ目の三角形の3頂点の座標を入力する */ printf("Input 1st triangle:\n"); InputTriangle( &tri1 ); /* 1つ目の三角形の面積を求める */ area1 = CalcArea( tri1 ); while (area1 == 0.0) { printf("These points do not form a triangle!\n"); printf("Again, input 1st triangle:\n"); InputTriangle( &tri1 ); area1 = CalcArea( tri1 ); } /* 2つ目の三角形の3頂点の座標を入力する */ printf("Input 2nd triangle:\n"); InputTriangle( &tri2 ); /* 2つ目の三角形の面積を求める */ area2 = CalcArea( tri2 ); while (area2 == 0.0) { printf("These points do not form a triangle!\n"); printf("Again, input 2nd triangle:\n"); InputTriangle( &tri2 ); area2 = CalcArea( tri2 ); } /* CalcAreaで求めた三角形の面積を2つ表示 */ printf("\nArea of 1st one: %.3f Area of 2nd one: %.3f\n", area1, area2); /* 面積の大きい方を判定して、表示 */ if (area1 == area2) printf("The two triangles have the same area!\n\n"); else if (area1 > area2) printf("The 1st one is larger than the 2nd one!\n\n"); else printf("The 2nd one is larger than the 1st one!\n\n"); /* 1つ目の三角形の重心を求める */ centroid1 = CalcCentroid( tri1 ); /* 2つ目の三角形の重心を求める */ centroid2 = CalcCentroid( tri2 ); /* GetCentroidで求めた三角形の重心を2つ表示 */ printf("Centroid of 1st one: (%.3f, %.3f)\n", centroid1.x, centroid1.y); printf("Centroid of 2nd one: (%.3f, %.3f)\n", centroid2.x, centroid2.y); return 0; }