Даны координаты трех вершин треугольника (x1,y1), (x2,y2), (x3,y3). Найти его периметр и площадь.
Входной формат: Три пары целых чисел - координаты вершин треугольника
Выходной формат: Два вещественных числа - периметр и площадь.
Примеры: Ввод: 0 0 3 0 3 4 Выход: 12.0 6.0
Написал такой код:
#include
#include
int main () {
int x1,x2,x3,y1,y2,y3,a,b,c;
float p,s,p2;
scanf("%i %i %i %i %i %i",&x1,&y1,&x2,&y2,&x3,&y3);
a=sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));
b=sqrt(((x2-x3)*(x2-x3))+((y2-y3)*(y2-y3)));
c=sqrt(((x3-x1)*(x3-x1))+((y3-y1)*(y3-y1)));
p=a+b+c;
p2=p/2;
s=sqrt(p2*(p2-a)*(p2-b)*(p2-c));
printf("%.1f %.1f",p,s);
}
А проверяющая система пишет, неправильный ответ. Хотя ответ выводит такой же.
C/C++
Помогите найти ошибку
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
typedef struct {
int x;
int y;
} Point;
typedef struct {
Point a;
Point b;
Point c;
} Triangle;
typedef struct {
double a;
double b;
double c;
} Box;
double length(Point* a, Point* b) {
return sqrt(pow(a->x - b->x, 2) + pow(a->y - b->y, 2));
}
Box lines(Triangle* t) {
Box box;
box.a = length(&t->a, &t->b);
box.b = length(&t->b, &t->c);
box.c = length(&t->c, &t->a);
return box;
}
double pp(Box* x) {
return (x->a + x->b + x->c) / 2;
}
double param(Box* x) {
double p = pp(x);
return (p - x->a) * (p - x->b) * (p - x->c);
}
_Bool exist(Triangle* t) {
Box x = lines(t);
double p = pp(&x);
return param(&x) > 0;
}
double perimeter(Triangle* t) {
Box x = lines(t);
return x.a + x.b + x.c;
}
double area(Triangle* t) {
Box x = lines(t);
double p = pp(&x);
return sqrt(p * param(&x));
}
Point coord(const char* point) {
Point p;
printf("%sx: ", point);
scanf_s("%i", &p.x);
printf("%sy: ", point);
scanf_s("%i", &p.y);
return p;
}
Triangle coords() {
Triangle t;
t.a = coord("A");
t.b = coord("B");
t.c = coord("C");
return t;
}
int main(void) {
Triangle t = coords();
if (exist(&t)) {
double p = perimeter(&t);
double a = area(&t);
printf("%.1lf %.1lf\n", p, a);
}
system("pause > nul");
return 0;
}
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
typedef struct {
int x;
int y;
} Point;
typedef struct {
Point a;
Point b;
Point c;
} Triangle;
typedef struct {
double a;
double b;
double c;
} Box;
double length(Point* a, Point* b) {
return sqrt(pow(a->x - b->x, 2) + pow(a->y - b->y, 2));
}
Box lines(Triangle* t) {
Box box;
box.a = length(&t->a, &t->b);
box.b = length(&t->b, &t->c);
box.c = length(&t->c, &t->a);
return box;
}
double pp(Box* x) {
return (x->a + x->b + x->c) / 2;
}
double param(Box* x) {
double p = pp(x);
return (p - x->a) * (p - x->b) * (p - x->c);
}
_Bool exist(Triangle* t) {
Box x = lines(t);
double p = pp(&x);
return param(&x) > 0;
}
double perimeter(Triangle* t) {
Box x = lines(t);
return x.a + x.b + x.c;
}
double area(Triangle* t) {
Box x = lines(t);
double p = pp(&x);
return sqrt(p * param(&x));
}
Point coord(const char* point) {
Point p;
printf("%sx: ", point);
scanf_s("%i", &p.x);
printf("%sy: ", point);
scanf_s("%i", &p.y);
return p;
}
Triangle coords() {
Triangle t;
t.a = coord("A");
t.b = coord("B");
t.c = coord("C");
return t;
}
int main(void) {
Triangle t = coords();
if (exist(&t)) {
double p = perimeter(&t);
double a = area(&t);
printf("%.1lf %.1lf\n", p, a);
}
system("pause > nul");
return 0;
}
a, b, c не должны быть целыми
Hasan Abdulla
Их во float перенести?
Hasan Abdulla
Приняло, спасибо
Похожие вопросы
- Помогите найти ошибку в коде
- С++ Win32 Api Помогите найти ошибку.
- Программа не выполняет условия задания, исходный массив меняет сам себя, помогите найти ошибку
- Помогите найти ошибки в коде на C++, не выводится последняя строчка
- Помогите найти ошибку.Где ошибка в коде не могу найти язык СИ
- Помогите найти ошибку в тесте на последовательности бит C++
- С++. Помогите найти ошибку в коде.
- Помогите найти ошибку в коде!!!
- Помогите найти ошибки в коде c++
- Помогите найти ошибку в коде