Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ЗАДАНИЕ 1.15
- // Треугольник задан координатами своих вершин.
- // Найти периметр и площадь треугольника.
- #include <stdio.h> // Для ВВОДА и ВЫВОДА
- #include <math.h> // Для sqrt() и abs()
- #include <stdlib.h> // Для abs()
- using namespace std; // ПРОСТРАНСТВО ИМЁН
- int main() {
- // ОБЪЯВЛЕНИЕ и ОПРЕДЕЛЕНИЕ (ввод) переменных (точек)
- int x1, y1, x2, y2, x3, y3;
- printf("Enter x1: ");
- scanf("%d", &x1);
- printf("Enter y1: ");
- scanf("%d", &y1);
- printf("Enter x2: ");
- scanf("%d", &x2);
- printf("Enter y2: ");
- scanf("%d", &y2);
- printf("Enter x3: ");
- scanf("%d", &x3);
- printf("Enter y3: ");
- scanf("%d", &y3);
- // Подсчет ПЕРИМЕТРА
- float per = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) +
- sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)) +
- sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
- // Подсчет ПЛОЩАДИ
- float square = 0.5 * abs((x1 - x3) * (y2 - y3) - (y1 - y3) * (x2 - x3));
- // ВЫВОД РЕЗУЛЬТАТА
- printf("Result: %f %f\n", per, square);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement