Untitled

mail@pastecode.io avatarunknown
c_cpp
a month ago
1.4 kB
2
Indexable
Never
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <windows.h>

// заполнить одномерный массив структур (точка на плоскости) и вывести на экран
// (12; 65) (45; 18) (67; 98) ..
// размер массива вводит пользователь

// найти ближайшую точки к началу координат

typedef struct Point {
    int x, y;
} Point;

void FillArr( Point* arr, const int n ){
    int i;
    for (i = 0; i < n; i++ )
        arr[ i ].x = rand() % 101 - 50;
        arr[ i ].y = rand() % 101 - 50;

}
void PrintArr(Point *arr, const int n) {
    int i;
    for (i = 0; i < n; i ++) {
            printf("%d", arr[i]);

    }
}

    // НЕЛЬЗЯ arr[ i ] = rand() % 101 - 50

    // НУЖНО
    // arr[ i ].x = rand() % 101 - 50
    // arr[ i ].y = rand() % 101 - 50




int main()
{
    SetConsoleCP(1251);
    SetConsoleOutputCP(1251);
    int n;
    printf("Введите размер массива: ");
    scanf("d", &n);
    Point* points = (Point*)malloc( n * sizeof( Point ) );
    if( points == NULL ){
        puts("Memory allocation error");
        return 1;
    }
    srand( time( NULL ) );
    FillArr(points,n );
    PrintArr (points,n);
    free(points);
    return 0;
}