C/C++

Программирование, нужна помощь в решение задачи! На си или си++

Пользователь вводит с клавиатуры координаты трех точек: A (x1, y1), B (x2, y2), C (x3, y3). Составьте программу, выводящую на экран координаты той точки, которая расположена ближе всех к центру координат (0, 0), и длину до него. Переменные, хранящие координаты точек имеют тип double.
А нужно прям на си? Там посчитать расстояние через координаты, сравнить и вывести. Легко, но я не знаю си. Только Python
Ion Tihon
Ion Tihon
1 288
Лучший ответ
Айдос Альменов В этом то и проблема что ответы на питоне я балбес уже нашел))) а на си был код где можно было найти ближайшую точку, но расстояния там небыло
Ion Tihon Там кв корень из суммы квадратов разности координат
Ion Tihon В интернете есть функция вывода, но в си непростой синтаксис, нужно правильно написать
Ion Tihon Есть киберфорум, там должны помочь с этим
Вот решение твоей задачи на C:

#include <stdio.h>
#include <math.h>

int main() {
double x1, y1, x2, y2, x3, y3;
double min_distance = -1; // Initialize to -1 to handle the case where all points are at the origin
double closest_x, closest_y;

// Read in the coordinates of the three points
printf("Enter the coordinates of point A: ");
scanf("%lf%lf", &x1, &y1);
printf("Enter the coordinates of point B: ");
scanf("%lf%lf", &x2, &y2);
printf("Enter the coordinates of point C: ");
scanf("%lf%lf", &x3, &y3);

// Check the distance from the origin to each point and update the minimum distance and closest point if necessary
double distance = sqrt(x1 * x1 + y1 * y1); // Distance from origin to point A
if (min_distance < 0 || distance < min_distance) {
min_distance = distance;
closest_x = x1;
closest_y = y1;
}

distance = sqrt(x2 * x2 + y2 * y2); // Distance from origin to point B
if (min_distance < 0 || distance < min_distance) {
min_distance = distance;
closest_x = x2;
closest_y = y2;
}

distance = sqrt(x3 * x3 + y3 * y3); // Distance from origin to point C
if (min_distance < 0 || distance < min_distance) {
min_distance = distance;
closest_x = x3;
closest_y = y3;
}

// Print the result
printf("The closest point to the origin is (%.2f, %.2f) with a distance of %.2f.\n", closest_x, closest_y, min_distance);

return 0;
}
Айдос Альменов Спс большое, тебе уже дало награду, или как тут всё работает?)