|
@@ -8,6 +8,59 @@
|
|
|
#define PRECISION "%.2f"
|
|
|
#define FULL_PRECISION "%.3f"
|
|
|
|
|
|
+#define SQUARE(x) ((x) * (x))
|
|
|
+//Ìàêðîñ äëÿ ðàñ÷åòà äëèíû îòðåçêà
|
|
|
+#define LENGTH(x1, y1,x2,y2) (sqrt(SQUARE(x2 - x1) + SQUARE(y2 - y1)))
|
|
|
+//äèðåêòèâû äëÿ ðåæèìà âû÷èñëåíèÿ
|
|
|
+#define MODE 2 // 1 - äëèíà îòðåçêà, 2 - ïðîâåðêà òðåóãîëüíèêà
|
|
|
+
|
|
|
+#if MODE == 1
|
|
|
+void calculate_otrezok() {
|
|
|
+ //Ââîä êîîðäèíàò äëÿ íàõîæäåíèÿ äëèíû îòðåçêà
|
|
|
+ double x1, y1, x2, y2, x3, y3;
|
|
|
+ printf("\nÂâåäèòå êîîðäèíàòû ïåðâîé òî÷êè: ");
|
|
|
+ scanf("%lf %lf", &x1, &y1);
|
|
|
+ printf("Ââåäèòå êîîðäèíàòû âòîðîé òî÷êè: ");
|
|
|
+ scanf("%lf %lf", &x2, &y2);
|
|
|
+ double lenght = LENGTH(x1, y1, x2, y2);
|
|
|
+ printf("Äëèíà îòðåçêà: %.2f\n", lenght);
|
|
|
+}
|
|
|
+
|
|
|
+#elif MODE == 2
|
|
|
+void calculate_triangle() {
|
|
|
+ double x1, y1, x2, y2, x3, y3;
|
|
|
+ printf("\nÂâåäèòå êîîðäèíàòû ïåðâîé òî÷êè: ");
|
|
|
+ scanf("%lf %lf", &x1, &y1);
|
|
|
+ printf("Ââåäèòå êîîðäèíàòû âòîðîé òî÷êè: ");
|
|
|
+ scanf("%lf %lf", &x2, &y2);
|
|
|
+ printf("Ââåäèòå êîîðäèíàòû òðåòüåé òî÷êè: ");
|
|
|
+ scanf("%lf %lf", &x3, &y3);
|
|
|
+ //Âû÷èñëåíèå äëèí ñòîðîí òðåóãîëüíèêà
|
|
|
+ double side1 = LENGTH(x1, y1, x2, y2);
|
|
|
+ double side2 = LENGTH(x2, y2, x3, y3);
|
|
|
+ double side3 = LENGTH(x3, y3, x1, y1);
|
|
|
+
|
|
|
+ //Ïðîâåðêà ñóùåñòâîâàâíèÿ òðåóãîëüíèêà
|
|
|
+ if ((side1 + side2 > side3) && (side2 + side3 > side1) && (side3 + side1 > side2)) {
|
|
|
+ //Ïåðèìåòð
|
|
|
+ double perimeter = side1 + side2 + side3;
|
|
|
+ printf("Òðåóãîëüíèê ñóùåñòâóåò\n");
|
|
|
+ printf("Ïåðèìåòð òðåóãîëüíèêà: %.2f\n", perimeter);
|
|
|
+
|
|
|
+ //Ïëîùàäü
|
|
|
+ double semi_perimeter = perimeter / 2;
|
|
|
+ double S = sqrt(semi_perimeter * (semi_perimeter - side1) * (semi_perimeter - side2) * (semi_perimeter - side3));
|
|
|
+ printf("Ïëîùàäü òðåóãîëüíèêà: %.2f\n", S);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ printf("Òðåóãîëüíèê íå ñóùåñòâóåò\n");
|
|
|
+ }
|
|
|
+}
|
|
|
+#else
|
|
|
+void no_mode() {
|
|
|
+ printf("\nÍåèçâåñòíûé ðåæèì âû÷èñëåíèÿ. \n");
|
|
|
+}
|
|
|
+#endif
|
|
|
int main()
|
|
|
{
|
|
|
system("chcp 1251>null");
|
|
@@ -37,6 +90,15 @@ int main()
|
|
|
//ñòðîêà â ÷èñëî
|
|
|
double number = string_to_double(STR_TO_CONVERT);
|
|
|
printf("Ïðåîáðàçîâàííîå çíà÷åíèå: " FULL_PRECISION "\n", number);
|
|
|
+
|
|
|
+#if MODE == 1
|
|
|
+ calculate_otrezok();
|
|
|
+#elif MODE == 2
|
|
|
+ calculate_triangle();
|
|
|
+#else
|
|
|
+ no_mode();
|
|
|
+#endif
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|