X, Y 좌표를 3개 받아서 삼각형의 결정 여부 구하기

2008. 11. 2. 11:57ETC Programmings

반응형

             int x1, x2, x3, y1, y2 ,y3, isAvailable;

             double oneToTwo, oneToThree, twoToThree;

             double first, second, third;

             printf("첫번째x좌표입력");

             scanf("%d", &x1);

             printf("첫번째y좌표입력");

             scanf("%d", &y1);

             printf("두번째x좌표입력");

             scanf("%d", &x2);

             printf("두번째y좌표입력");

             scanf("%d", &y2);

             printf("세번째x좌표입력");

             scanf("%d", &x3);

             printf("세번째y좌표입력");

             scanf("%d", &y3);

             printf("입력한좌표는: (%d,%d) (%d,%d) (%d,%d)\n", x1, y1, x2, y2, x3, y3);

             oneToTwo = sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));

             oneToThree = sqrt((x1 - x3)*(x1 - x3) + (y1 - y3)*(y1 - y3));

             twoToThree = sqrt((x2 - x3)*(x2 - x3) + (y2 - y3)*(y2 - y3));

             isAvailable = 0;

             if (oneToTwo > abs(oneToThree - twoToThree) && oneToTwo < oneToThree + twoToThree)

                           if(oneToThree > abs(oneToTwo - twoToThree) && oneToThree < oneToTwo + twoToThree)

                                        if(twoToThree > abs(oneToTwo - oneToThree) && twoToThree < oneToTwo + oneToThree)

                                                     isAvailable = 1;

             if(isAvailable)

                           printf("삼각형가능\n");

             else

                           printf("삼각형불가\n");

 

반응형