Advertisement
LightProgrammer000

Struct [Posição(X,Y)]

Dec 1st, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.84 KB | None | 0 0
  1. //////////// Programa Difícil ////////////
  2.  
  3. #include <time.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. #define SIZE 5
  8.  
  9. // Estrutura Global
  10. struct bot
  11. {
  12.     int xpos;
  13.     int ypos;
  14. };
  15.  
  16. // Prototipação - Formato Estrutura
  17. struct bot funcao(struct bot b);
  18.  
  19. int main()
  20. {
  21.     // Declaração de variáveis
  22.     int i;
  23.     struct bot robots[SIZE];// Instanciação de objeto "robots"
  24.  
  25.     // Controle de números randômicos
  26.     srand( (unsigned) time(NULL) );
  27.  
  28.     for( i = 0; i < SIZE; i++ )
  29.     {
  30.         robots[i] = funcao(robots[i]);
  31.  
  32.         printf("\n Robot %d: Coordinates: %d,%d \n", i + 1, robots[i].xpos, robots[i].ypos);
  33.     }
  34.  
  35.     return(0);
  36. }
  37.  
  38. struct bot funcao(struct bot b)
  39. {
  40.     int x,y;
  41.  
  42.     x = rand();
  43.     x %= 20;
  44.  
  45.     y = rand();
  46.     y %= 20;
  47.  
  48.     b.xpos = x;
  49.     b.ypos = y;
  50.  
  51.     return(b);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement