traceonelast

Kn15_lb9var9

Dec 27th, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1. // КН-15 лр9вар9.cpp: определяет точку входа для консольного приложения.
  2. //
  3. #include "stdafx.h"
  4. #include <stdlib.h>
  5. #include <iostream>
  6. #include "conio.h"
  7. #include "time.h"
  8. #pragma warning(disable: 4996)
  9. int main()
  10. {
  11.     setlocale(LC_ALL, "Russian");
  12.     srand(time(NULL));
  13.  
  14.     float x[300], y[300], r[300];
  15.     int max = 0;
  16.     int m;
  17.     int count = 0;
  18.     float d;
  19.     printf("Количество окружностей \n");
  20.     scanf("%d", &m);
  21.  
  22.     for (int i = 0; i < m; i++)
  23.     {
  24.         x[i] = (rand() % 300) / 10.0;
  25.         y[i] = (rand() % 300) / 10.0;
  26.         r[i] = 5+ rand() % 100 /10.0;
  27.  
  28.     }
  29.     for (int i = 0; i < m-1; i++)
  30.     {
  31.         d = sqrt(powf(x[i + 1] - x[i], 2) + powf(y[i + 1] - y[i], 2));
  32.         if (d < (r[i] + r[i + 1])) count++;
  33.         else if (count>max) { max = count; count = 0; }
  34.         else count = 0;;
  35.     }
  36.     printf("\n___________\n");
  37.     printf("X     Y   r\n");
  38.     printf("___________\n");
  39.     for (int i = 0; i < m; i++)
  40.         printf("%.1f  %.1f  %.1f\n", x[i], y[i],r[i]);
  41.  
  42.     printf("\nСамая длинная цепочка из  %d окружностей", max);
  43.     _getch();
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment