[Code example] struct middel point page 130

User avatar

Topic author
BJT
Site Admin
Site Admin
Posts: 141
Joined: Thu Apr 20, 2017 4:43 pm
Instruction: University Student
Gender:
Age: 27
Venezuela

struct middel point page 130

Post by BJT » Sat May 13, 2017 10:06 pm

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define XMAX 45
  5. #define YMAX 50
  6.  
  7. struct point
  8. {
  9.     int x;
  10.     int y;
  11. };
  12.  
  13. struct rect
  14. {
  15.     struct point pt1;
  16.     struct point pt2;
  17. };
  18.  
  19. struct point makepoint(int x, int y);
  20.  
  21. int main()
  22. {
  23.     struct rect screen;
  24.     struct point middle;
  25.  
  26.     screen.pt1=makepoint(0,0);
  27.     screen.pt2=makepoint(XMAX,YMAX);
  28.     middle=makepoint((screen.pt1.x+screen.pt2.x)/2,(screen.pt1.y+screen.pt2.y)/2);
  29.     printf("%d %d\n",middle.x,middle.y);
  30.     return EXIT_SUCCESS;
  31. }
  32.  
  33. struct point makepoint(int x, int y)
  34. {
  35.     struct point temp;
  36.     temp.x=x;
  37.     temp.y=y;
  38.     return temp;
  39. }

output

Code: Select all

22 25
word count: 110

Link:
BBcode:
HTML:
Hide post links
Show post links

Who is online

Users browsing this forum: No registered users and 2 guests