Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <locale.h>
- struct Coords
- {
- float x;
- float y;
- float distance;
- };
- float distance(float x, float y)
- {
- return sqrt(pow(x, 2) + pow(y, 2));
- }
- void input(struct Coords *ptr, unsigned int n)
- {
- for (unsigned int i = 0; i < n; i++)
- {
- printf("Введите x для %u точки\n", i + 1);
- scanf("%f", &(ptr + i)->x);
- printf("Введите y для %u точки\n", i + 1);
- scanf("%f", &(ptr + i)->y);
- (ptr + i)->distance = distance((ptr + i)->x, (ptr + i)->y);
- }
- }
- void output(struct Coords *ptr ,unsigned int index)
- {
- printf("Самая отдаленная точка имеет координаты x - %f, y - %f\n", (ptr + index)->x, (ptr + index)->y);
- }
- void main()
- {
- setlocale(LC_ALL, "");
- printf("Введите количество точек\n");
- unsigned int n, index = 0;
- scanf("%u", &n);
- Coords coordinates[100], *pointer;
- input(coordinates, n);
- float max_dist = coordinates->distance;
- for (unsigned int i = 0; i < n; i++)
- {
- if ((pointer + i)->distance > max_dist)
- {
- max_dist = (pointer + i)->distance;
- index = i;
- }
- }
- output(coordinates, index);
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement