На проверку ДЗ 37
На проверку ДЗ 37unknown
c_cpp
a year ago
1.7 kB
4
Indexable
Never
#include <stdio.h> #include <stdlib.h> // проект 24, Point points[ n ]; // не использовать операцию индексации [] int main() { typedef struct Point { int* x, y; // -- присваиваем ячейкам постоянное значение } Point; double Distance( Point p ){ return sqrt( p.x * p.x, p.y * p.y ); } int main() { const int* n = 5; // n - присваивается определенная ячейка в памяти = 5 int* i; Point points(&n); // считывается определенное значение ячейки =5 в памяти переменной "n" //scanf("%d%d", &points[0].x, &points[0].y) puts("Enter coordinates five of points:"); for (i = 0; i < &n; i++) { printf("%d: ", i + 1); scanf("%d%d", &points+i.x, &points+i.y); // поскольку *A = A+ i } int* j; for (i = 0; i < &n - 1; i++) { for (j = 0; j < n - i - 1; j++) { //double distCurr = Distance( points[j] );// sqrt( points[j].x * points[j].x + points[j].y * points[j].y ); //double distNext = sqrt( points[j + 1].x * points[j + 1].x + points[j + 1].y * points[j + 1].y ); if (Distance(points(&j)) > Distance(points(&j+1))) { Point tmp = points(&j); // tmp.x = points[ j ].x; tmp.y = points[ j ].y points(&j) = points(&j+1); points(&j+1) = tmp; } } } printf("Sorting points are: \n"); for (i = 0; i < n; i++){ printf("(%d; %d) ", points(&i).x, points(&i).y); } return 0; }