Advertisement
daniil_mironoff

Ex. 1.15

May 20th, 2019
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. // ЗАДАНИЕ 1.15
  2. // Треугольник задан координатами своих вершин.
  3. // Найти периметр и площадь треугольника.
  4.  
  5. #include <stdio.h>   // Для ВВОДА и ВЫВОДА
  6. #include <math.h>    // Для sqrt() и abs()
  7. #include <stdlib.h>  // Для abs()
  8.  
  9. using namespace std; // ПРОСТРАНСТВО ИМЁН
  10.  
  11. int main() {
  12.     // ОБЪЯВЛЕНИЕ и ОПРЕДЕЛЕНИЕ (ввод) переменных (точек)
  13.     int x1, y1, x2, y2, x3, y3;
  14.     printf("Enter x1: ");
  15.     scanf("%d", &x1);
  16.     printf("Enter y1: ");
  17.     scanf("%d", &y1);
  18.     printf("Enter x2: ");
  19.     scanf("%d", &x2);
  20.     printf("Enter y2: ");
  21.     scanf("%d", &y2);
  22.     printf("Enter x3: ");
  23.     scanf("%d", &x3);
  24.     printf("Enter y3: ");
  25.     scanf("%d", &y3);
  26.    
  27.     // Подсчет ПЕРИМЕТРА
  28.     float per = sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) +
  29.                 sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3)) +
  30.                 sqrt((x3 - x1) * (x3 - x1) + (y3 - y1) * (y3 - y1));
  31.    
  32.     // Подсчет ПЛОЩАДИ
  33.     float square = 0.5 * abs((x1 - x3) * (y2 - y3) - (y1 - y3) * (x2 - x3));
  34.    
  35.     // ВЫВОД РЕЗУЛЬТАТА
  36.     printf("Result: %f %f\n", per, square);
  37.    
  38.     return 0;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement