C/C++
Задача на языке си!!!
Треугольник задается координатами своих вершин на плоскости: A(x1, y1), В (х2,, у2), С (х3, y3). Найти площадь треугольника ABC.
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
typedef struct {
double x;
double y;
} Point;
double coord(const char* msg) {
double value;
printf(msg);
scanf_s("%lf", &value);
while (getchar() != '\n');
return value;
}
Point coords(const char* msg) {
Point p;
printf(msg);
p.x = coord("x: ");
printf(msg);
p.y = coord("y: ");
return p;
}
typedef struct {
Point a;
Point b;
Point c;
} CoordsTriangle;
CoordsTriangle create() {
CoordsTriangle t;
t.a = coords("A");
t.b = coords("B");
t.c = coords("C");
return t;
}
typedef struct {
double a;
double b;
double c;
} LengthTriangle;
double length(Point* pa, Point* pb) {
return sqrt(pow(pa->x - pb->x, 2) + pow(pa->y - pb->y, 2));
}
LengthTriangle init(CoordsTriangle* pct) {
LengthTriangle lt;
lt.a = length(&pct->a, &pct->b);
lt.b = length(&pct->b, &pct->c);
lt.c = length(&pct->c, &pct->a);
return lt;
}
double perimeter(LengthTriangle* lt) {
return lt->a + lt->b + lt->c;
}
double arg(LengthTriangle* lt) {
double p = perimeter(lt) / 2;
return p * (p - lt->a) * (p - lt->b) * (p - lt->c);
}
double area(CoordsTriangle* ct) {
LengthTriangle lt = init(ct);
double x = arg(<);
if (x > 0) return sqrt(x);
return 0;
}
int main(void) {
CoordsTriangle ct = create();
double s = area(&ct);
if (s) printf("Area: %.4lf\n", s);
else puts("Triangle not exist!");
system("pause > nul");
return 0;
}
#include <stdio.h>
#include <math.h>
typedef struct {
double x;
double y;
} Point;
double coord(const char* msg) {
double value;
printf(msg);
scanf_s("%lf", &value);
while (getchar() != '\n');
return value;
}
Point coords(const char* msg) {
Point p;
printf(msg);
p.x = coord("x: ");
printf(msg);
p.y = coord("y: ");
return p;
}
typedef struct {
Point a;
Point b;
Point c;
} CoordsTriangle;
CoordsTriangle create() {
CoordsTriangle t;
t.a = coords("A");
t.b = coords("B");
t.c = coords("C");
return t;
}
typedef struct {
double a;
double b;
double c;
} LengthTriangle;
double length(Point* pa, Point* pb) {
return sqrt(pow(pa->x - pb->x, 2) + pow(pa->y - pb->y, 2));
}
LengthTriangle init(CoordsTriangle* pct) {
LengthTriangle lt;
lt.a = length(&pct->a, &pct->b);
lt.b = length(&pct->b, &pct->c);
lt.c = length(&pct->c, &pct->a);
return lt;
}
double perimeter(LengthTriangle* lt) {
return lt->a + lt->b + lt->c;
}
double arg(LengthTriangle* lt) {
double p = perimeter(lt) / 2;
return p * (p - lt->a) * (p - lt->b) * (p - lt->c);
}
double area(CoordsTriangle* ct) {
LengthTriangle lt = init(ct);
double x = arg(<);
if (x > 0) return sqrt(x);
return 0;
}
int main(void) {
CoordsTriangle ct = create();
double s = area(&ct);
if (s) printf("Area: %.4lf\n", s);
else puts("Triangle not exist!");
system("pause > nul");
return 0;
}

https://www.onlinegdb.com/Hk7yzkDDu Вот вам мой пример для работы с фигурами. Там имеется класс Triangle - возьмите от туда формулу.
Похожие вопросы
- Помогите с решением задачи на языке СИ
- Решить задачу на языке СИ
- Помогите с задачей на языке СИ
- Помогите с 4 задачей на языке си
- Помогите пожалуйста доделать задачу на языке СИ!!!
- Помогите пожалуйста решить задачу на языке СИ или С# !!!
- Помогите решить задачу, пожалуйста. (Язык Си)
- Решите пожалуйста задачу на языке Си!!!
- Задача на языке си++
- Написать программу на языке Си, которая решит эту задачу: