Back
#include<stdio.h>
#define XMAX 10
#define YMAX 20
struct point
{
int x;
int y;
};
struct rect
{
struct point pt1;
struct point pt2;
};
struct point middle;
struct rect screen;
struct point makepoint(int x, int y);
struct point addpoint (struct point p1, struct point p2);
int ptinrect(struct point p, struct rect r);
int main()
{
screen.pt1 = makepoint(0,0);
screen.pt2 = makepoint(XMAX, YMAX);
middle = makepoint ((screen.pt1.x + screen.pt2.x)/2 , (screen.pt1.y + screen.pt2.y)/2);
printf("Middle = %d, %d\n",middle.x, middle.y);
struct point pt3 = makepoint(XMAX, YMAX);
printf("Sum = %d , %d\n", addpoint(middle, pt3));
struct rect r = {{0,0},{30,30}};
printf("Point in rectangle: %s\n", ptinrect(pt3,r) ? "TRUE" : "FALSE");
return 0;
}
struct point makepoint(int x, int y)
{
struct point temp;
temp.x = x;
temp.y = y;
return temp;
}
struct point addpoint(struct point p1, struct point p2)
{
p1.x += p2.x;
p1.y += p2.y;
return p1;
}
int ptinrect(struct point p, struct rect r)
{
return (p.x >= r.pt1.x && p.x < r.pt2.x && p.y >= r.pt1.y && p.y < r.pt2.y);
}
Top