Advertisement
Guest User

Untitled

a guest
Apr 29th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. typedef float reale;
  6. typedef struct _dot
  7.     {
  8.         reale x;
  9.         reale y;
  10.     } dot;
  11. typedef dot* pdot;
  12.  
  13. pdot crea_punto(reale x, reale y)
  14.     {
  15.         pdot pd;
  16.         pd=(pdot)malloc(sizeof(dot));
  17.         if(pd!=NULL)
  18.             {
  19.                 pd->y=y; pd->x=x;          
  20.             }
  21.         return pd;
  22.     }
  23. void free_punto(pdot pd)
  24.     {
  25.         free(pd);
  26.     }
  27. pdot punto_random(void)
  28.     {
  29.         return crea_punto(((reale)rand())/RAND_MAX,((reale)rand())/RAND_MAX);
  30.     }
  31. reale distanza_punto_origine(pdot pd)
  32.     {
  33.         return sqrt((pd->x*pd->x)+(pd->y*pd->y));
  34.     }
  35. void stampa_punto(pdot pd)
  36.     {
  37.         printf("\n(%f,%f)",pd->x,pd->y);
  38.     }
  39. void main (void)
  40.     {
  41.         pdot pd1,pd2;
  42.         pd1=crea_punto(1,2);
  43.         printf("\nIl punto random generato è : ");
  44.         stampa_punto(pd1);
  45.         printf("\nLa distanza dall'origine vale : %f",distanza_punto_origine(pd1));
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement