Advertisement
Guest User

Untitled

a guest
Dec 17th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.81 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <malloc.h>
  5.  
  6. typedef struct
  7. {
  8.     float x, y, z;
  9. } tochka;
  10.  
  11. typedef struct
  12. {
  13.     tochka A, B;
  14. } pryamaya;
  15.  
  16. int input (pryamaya *p, int n)
  17. {
  18.     int i;
  19.     for (i=0; i<n; i++)
  20.     {
  21.         printf("Vvedite coordinati 1oi tochki %d pryamoi: ", i+1);
  22.         scanf("%f", &p[i].A.x);
  23.         scanf("%f", &p[i].A.y);
  24.         scanf("%f", &p[i].A.z);
  25.         printf("Vvedite coordinati 2oi tochki %d pryamoi: ", i+1);
  26.         scanf("%f", &p[i].B.x);
  27.         scanf("%f", &p[i].B.y);
  28.         scanf("%f", &p[i].B.z);
  29.     }
  30. }
  31.  
  32. int inicializaciya(int *p, int n)
  33. {
  34.     int i;
  35.     for (i=0; i<n; i++)
  36.         p[i]=0;
  37. }
  38.  
  39. int invector (pryamaya a, tochka c)
  40. {
  41.     c.x = a.B.x - a.A.x;
  42.     c.y = a.B.y - a.A.y;
  43.     c.z = a.B.z - a.A.z;
  44. }
  45.  
  46. int parallelnost(pryamaya a, pryamaya b)
  47. {
  48.     tochka c, d;
  49.     c.x=0; c.y=0; c.z=0;
  50.     d.x=0; d.y=0; d.z=0;
  51.     invector(a,c);
  52.     invector(b,d);
  53.     printf ("%f  %f  %f \n", c.x, c.y, c.z);
  54.     printf ("%f  %f  %f \n", d.x, d.y, d.z);
  55.     if ((c.x*d.y == c.y*d.x) && (c.z*d.y == c.y*d.z))
  56.         return 1;
  57.     else
  58.         return 0;
  59. }
  60.  
  61. int ClassEqvivalentnosty(pryamaya *p, int n)
  62. {
  63.     int i, j, k=0, *Q;
  64.     Q=(int*)malloc(n*sizeof(int));
  65.     inicializaciya(Q,n);
  66.     for (i=0; i<n; i++)
  67.     {
  68.         if (Q[i]==0)
  69.         {
  70.             k++;
  71.             for (j=n-1; j>=i; j--)
  72.                 if (parallelnost(p[i], p[j]))
  73.                     Q[j]=k;
  74.         }
  75.     }
  76.     free (Q);
  77.  return(k);
  78. }
  79.  
  80. int main()
  81. {
  82.     pryamaya *p;
  83.     int n;
  84.     printf("vvedite kol-vo pryamih: ");
  85.     scanf("%d", &n);
  86.     p=(pryamaya*)malloc(n*sizeof(pryamaya));
  87.     input(p,n);
  88.     printf("Klassov eqvivalentnosty: %d \n", ClassEqvivalentnosty(p,n));
  89.     free (p);
  90.     system("PAUSE");
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement