Advertisement
traceonelast

Kn15_lb9var17

Dec 23rd, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. // кн15 лр9вр17.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdlib.h>
  6. #include <iostream>
  7. #include "conio.h"
  8. #include "time.h"
  9. #pragma warning(disable: 4996)
  10. int main()
  11. {
  12.     setlocale(LC_ALL, "Russian");
  13.     srand(time(NULL));
  14.  
  15.     float x[100], y[100], z[100];
  16.     int m;
  17.     float rast[100];
  18.     float min = 10000, temp;
  19.     int n;
  20.     printf("Количество точек\n");
  21.     scanf("%d", &m);
  22.     printf("\nВведите параметр(количество точек в шарах) n\n");
  23.     scanf("%d", &n);
  24.     for (int i = 0; i < m; i++)
  25.     {
  26.         x[i] = (rand() % 100) / 10.0;
  27.         y[i] = (rand() % 100) / 10.0;
  28.         z[i] = (rand() % 100) / 10.0;
  29.    
  30.     }
  31.    
  32.     for (int i = 0; i < m; i++)
  33.     {
  34.         for (int j = 0; j < m; j++)
  35.         {
  36.             if (i == j) rast[j] = 0;
  37.             else rast[j] = abs(sqrt(powf((x[j] - x[i]), 2) + powf((y[j] - y[i]), 2) + powf((z[j] - z[i]), 2)));
  38.         }
  39.         for (int j = 0; j < m; j++)
  40.             for (int k = 0; k < m - 1; k++)
  41.             {
  42.                 if (rast[k] > rast[k + 1])
  43.                 {
  44.                     temp = rast[k];
  45.                     rast[k] = rast[k + 1];
  46.                     rast[k + 1] = temp;
  47.                 }
  48.             }
  49.         if (min > rast[n-1]) min = rast[n-1];
  50.     }
  51.     printf("_________________\n");
  52.     printf("i   X     Y     Z\n");
  53.     printf("_________________\n");
  54.     for (int i = 0; i < m; i++)
  55.         printf("%d  %.1f  %.1f  %.1f\n", i + 1, x[i], y[i], z[i]);
  56.    
  57.     printf("Радиус %.2f\n", min);
  58.     _getch();
  59.     return 0;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement