namereq

Untitled

Jun 14th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. typedef struct {
  6.     float x;    /* x */
  7.     float y;    /* y */
  8. } point;
  9.  
  10. point* random_point(){
  11.     srand((unsigned) time(NULL));
  12.     point* p = (point*)malloc(sizeof(point));
  13.     float rnd;
  14.     rnd = (rand() % 1001 - 500)/10.0;
  15.     p->x = rnd;
  16.     rnd = (rand() % 1001 - 500)/10.0;
  17.     p->y = rnd;
  18.     return p;
  19. }
  20.  
  21. int main(void)
  22. {
  23.     point* p;
  24.     p = random_point();
  25.     printf("生成された座標: (%.1f,%.1f)\n", p->x, p->y);
  26.     return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment