traceonelast

kn15_lb9var16

Dec 24th, 2015
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.95 KB | None | 0 0
  1. // КН15 лр9вар16.cpp: определяет точку входа для консольного приложения.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <stdlib.h>
  6. #include <iostream>
  7. #include "conio.h"
  8. #include "time.h"
  9. #include "math.h"
  10. #pragma warning(disable: 4996)
  11. int main()
  12. {
  13.     setlocale(LC_ALL, "Russian");
  14.     srand(time(NULL));
  15.  
  16.     float a[100], b[100], c[100],dot[100][100];
  17.     int cross[100];
  18.     int m;
  19.    
  20.     int  count = 0;
  21.     float temp;
  22.     printf("Количество прямых\n");
  23.     scanf("%d", &m);
  24.    
  25.     for (int i = 0; i < m; i++)
  26.     {
  27.         cross[i] = 0;
  28.         a[i] = rand() % 10;
  29.         b[i] = rand() % 10;
  30.         c[i] = rand() % 10;
  31.  
  32.     }
  33.     for (int i = 0; i < m-1; i++)
  34.     {
  35.         for (int j = i+1; j < m; j++)
  36.         {
  37.             if (i != j)
  38.             {  
  39.                 if ((a[i]*b[j]-a[j]*b[i])!=0)
  40.                 {
  41.                     dot[0][count] = round( (-(c[i] * b[j] - c[j] * b[i]) / (a[i] * b[j] - a[j] * b[i])));
  42.                     dot[1][count] = round((-(a[i] * c[j] - a[j] * c[i]) / (a[i] * b[j] - a[j] * b[i])));
  43.                     cross[i]++;
  44.                     cross[j]++;
  45.                     count++;
  46.                        
  47.                 }
  48.             }
  49.         }
  50.     }
  51.     for (int i = 0; i < count - 1; i++)
  52.     {
  53.         for (int j = i + 1; j < count; j++)
  54.         {
  55.             if (dot[0][i] == dot[0][j] && dot[1][i] == dot[1][j])
  56.             {
  57.                 for (int k = j; k < count; k++)
  58.                 {
  59.                     temp = dot[0][k];
  60.                     dot[0][k] = dot[0][k + 1];
  61.                     dot[0][k + 1] = temp;
  62.  
  63.                     temp = dot[1][k];
  64.                     dot[1][k] = dot[1][k + 1];
  65.                     dot[1][k + 1] = temp;
  66.                 }
  67.                 count--;
  68.             }
  69.         }
  70.     }
  71.     int min = 10000, mini;
  72.     for (int i = 0; i < m;i++)
  73.         if (min>cross[i]) { min = cross[i]; mini = i; }
  74.     printf("\nТочки пересечения прямых\n\n");
  75.     printf("___________\n");
  76.     printf("X     Y    \n");
  77.     printf("___________\n");
  78.     for (int i = 0; i < count; i++)
  79.         printf("%.1f  %.1f\n",dot[0][i],dot[1][i]);
  80.  
  81.     printf("\n Кол-во точек пересечений %d , номер прямой с минимальными пересечениями - %d", count,mini+1);
  82.     _getch();
  83.     return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment