[Code example] struct point inside of rectangel page 131

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 point inside of rectangel page 131

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

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct point
  5. {
  6.     int x;
  7.     int y;
  8. };
  9.  
  10. struct rect
  11. {
  12.     struct point pt1;
  13.     struct point pt2;
  14. };
  15.  
  16. int ptinrect(struct point p1, struct rect r);
  17.  
  18. int main()
  19. {
  20.     struct point p1={10,10};
  21.     struct rect rec1={{0,0},{100,100}};
  22.     printf("%d \n",ptinrect(p1,rec1));
  23.     return EXIT_SUCCESS;
  24. }
  25.  
  26. int ptinrect(struct point p, struct rect r)
  27. {
  28.     return p.x >= r.pt1.x && p.x < r.pt2.x && p.y >= r.pt1.y && p.y < r.pt2.y;
  29. }

output

Code: Select all

1
word count: 93

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

Who is online

Users browsing this forum: No registered users and 2 guests