[c] Σημεία σε κύβο 1x1x1

Viewer

copydownloadembedprintName: Σημεία σε κύβο 1x1x1
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5.  
  6. struct point
  7. {
  8.     double x;
  9.     double y;
  10.     double z;
  11. };
  12.  
  13. struct point input()
  14. {
  15.     struct point p;
  16.     p.x = (double)rand() / (double)RAND_MAX;
  17.     p.y = (double)rand() / (double)RAND_MAX;
  18.     p.z = (double)rand() / (double)RAND_MAX;
  19.     return p;
  20. }
  21.  
  22. double dist(struct point p1, struct point p2)
  23. {
  24.     double d;
  25.     d = sqrt(pow(p1.x - p2.x, 2) + pow(p1.y - p2.y, 2) + pow(p1.z - p2.z, 2));
  26.     return d;
  27. }
  28.  
  29. int main()
  30. {
  31.     srand(time(0));
  32.     int n, i, j, c1, c2, tests, i1, i2, i3, j1, j2, j3, k;
  33.     double max, s, mv, disTemp, firstMax, finalMax, firstMv, finalMv, difmax, amax, bmax, difmv, amv, bmv;
  34.     printf("Give number of points: ");
  35.     scanf("%d", &n);
  36.     struct point cube[n];
  37.     printf("Give number of tests: ");
  38.     scanf("%d", &tests);
  39.     double maxMatr[tests], mvMatr[tests];
  40.     for (= 0; k < tests; k++)
  41.     {
  42.         for (= 0; i < n; i++)
  43.         {
  44.             cube[i] = input();
  45.         }
  46.         max = dist(cube[0], cube[0]);
  47.         s = 0;
  48.         c1 = 0;
  49.         c2 = 0;
  50.         for (= 0; i < n; i++)
  51.         {
  52.             for (= i + 1; j < n; j++)
  53.             {
  54.                 disTemp = dist(cube[i], cube[j]);
  55.                 s = s + disTemp;
  56.                 if (disTemp > max)
  57.                 {
  58.                     max = disTemp;
  59.                     c1 = i;
  60.                     c2 = j;
  61.                 }
  62.             }
  63.         }
  64.         mv = (2 * s) / (* (+ 1));
  65.         maxMatr[k] = max;
  66.         mvMatr[k] = mv;
  67.     }
  68.     firstMax = maxMatr[0];
  69.     finalMax = maxMatr[0];
  70.     firstMv = mvMatr[0];
  71.     finalMv = mvMatr[0];
  72.  
  73.     for (= 0; i < tests; i++)
  74.     {
  75.         if (maxMatr[i] < firstMax)
  76.         {
  77.             firstMax = maxMatr[i];
  78.         }
  79.         else if (maxMatr[i] > finalMax)
  80.         {
  81.             finalMax = maxMatr[i];
  82.         }
  83.         if (mvMatr[i] < firstMv)
  84.         {
  85.             firstMv = mvMatr[i];
  86.         }
  87.         else if (mvMatr[i] > finalMv)
  88.         {
  89.             finalMv = mvMatr[i];
  90.         }
  91.     }
  92.     difmax = finalMax - firstMax;
  93.     amax = firstMax + difmax / 3;
  94.     bmax = finalMax - difmax / 3;
  95.     difmv = finalMv - firstMv;
  96.     amv = firstMv + difmv / 3;
  97.     bmv = finalMv - difmv / 3;
  98.     i1 = 0;
  99.     i2 = 0;
  100.     i3 = 0;
  101.     j1 = 0;
  102.     j2 = 0;
  103.     j3 = 0;
  104.     for (= 0; k < tests; k++)
  105.     {
  106.         if (maxMatr[k] < amax)
  107.         {
  108.             i1 = i1 + 1;
  109.         }
  110.         else if (maxMatr[k] < bmax)
  111.         {
  112.             i2 = i2 + 1;
  113.         }
  114.         else
  115.         {
  116.             i3 = i3 + 1;
  117.         }
  118.         if (mvMatr[k] < amv)
  119.         {
  120.             j1 = j1 + 1;
  121.         }
  122.         else if (mvMatr[k] < bmv)
  123.         {
  124.             j2 = j2 + 1;
  125.         }
  126.         else
  127.         {
  128.             j3 = j3 + 1;
  129.         }
  130.     }
  131.     printf("Maximum______\n");
  132.     printf("In [%lf,%lf]:%d \n", firstMax, amax, i1);
  133.     printf("In [%lf,%lf]:%d \n", amax, bmax, i2);
  134.     printf("In [%lf,%lf]:%d \n", bmax, finalMax, i3);
  135.     printf("Mean value_______\n");
  136.     printf("In [%lf,%lf]:%d \n", firstMv, amv, j1);
  137.     printf("In [%lf,%lf]:%d \n", amv, bmv, j2);
  138.     printf("In [%lf,%lf]:%d \n", bmv, finalMv, j3);
  139. }

Editor

You can edit this paste and save as new:


File Description
  • Σημεία σε κύβο 1x1x1
  • Paste Code
  • 23 Jan-2022
  • 3.23 Kb
You can Share it: