Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,943 questions

55,787 answers

573 users

How to check if a point is inside a rectangle in C

1 Answer

0 votes
#include <stdio.h>

typedef struct {
    double x, y;
} Point;

typedef struct {
    Point topLeft;
    Point bottomRight;
} Rectangle;

int isPointInsideRectangle(Point p, Rectangle rect) {
    return (p.x >= rect.topLeft.x && p.x <= rect.bottomRight.x &&
            p.y >= rect.topLeft.y && p.y <= rect.bottomRight.y);
}

int main() {
    Rectangle rect = {{0.0, 0.0}, {7.0, 7.0}};
    Point p = {3.0, 2.0};

    if (isPointInsideRectangle(p, rect)) {
        printf("The point is inside the rectangle.\n");
    } else {
        printf("The point is outside the rectangle.\n");
    }

    return 0;
}


   
/*
run:
   
The point is inside the rectangle.
 
*/

 



answered Jun 21, 2025 by avibootz

Related questions

...