Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- typedef float reale;
- typedef struct _dot
- {
- reale x;
- reale y;
- } dot;
- typedef dot* pdot;
- pdot crea_punto(reale x, reale y)
- {
- pdot pd;
- pd=(pdot)malloc(sizeof(dot));
- if(pd!=NULL)
- {
- pd->y=y; pd->x=x;
- }
- return pd;
- }
- void free_punto(pdot pd)
- {
- free(pd);
- }
- pdot punto_random(void)
- {
- return crea_punto(((reale)rand())/RAND_MAX,((reale)rand())/RAND_MAX);
- }
- reale distanza_punto_origine(pdot pd)
- {
- return sqrt((pd->x*pd->x)+(pd->y*pd->y));
- }
- void stampa_punto(pdot pd)
- {
- printf("\n(%f,%f)",pd->x,pd->y);
- }
- void main (void)
- {
- pdot pd1,pd2;
- pd1=crea_punto(1,2);
- printf("\nIl punto random generato รจ : ");
- stampa_punto(pd1);
- printf("\nLa distanza dall'origine vale : %f",distanza_punto_origine(pd1));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement