Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <time.h>
- #define COUNT 100
- typedef struct {
- double x;
- double y;
- } point;
- double distanceDecart(point,point);
- double maxDist(point pts[], int size){
- double max = 0;
- for (int i = 0; i < size; i++){
- for (int j = 0; j < size; j++){
- double dist = distanceDecart(pts[i], pts[j]);
- if (dist > max){
- max = dist;
- }
- }
- }
- return max;
- }
- int main(){
- srand(time(NULL));
- point points[COUNT];
- for (int i = 0; i < COUNT; i++){
- points[i].x = rand() % 11; // [0-10]
- points[i].y = rand() % 11;
- }
- for (int i = 0; i < COUNT; i++){
- printf("Point[%d] (%.1lf, %.1lf)\n", i, points[i].x, points[i].y);
- }
- double maxD = maxDist(points, COUNT);
- printf("Max distance: %.2lf\n", maxD);
- }
- double distanceDecart(point p1, point p2){
- return sqrt((p1.x-p2.x)*(p1.x-p2.x) + (p1.y-p2.y)*(p1.y-p2.y));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement