Friday, October 14, 2011

A rectangle with sides parallel to the X- and Y-axes is specified by four real numbers a, b, c, and d. Assume that a <= c and b <= d. The four corners of the rectangle are (a,b) [bottom left], (c,b) [bottom right], (a,d) [top left], and (c,d) [top right]. Read the values a1, b1, c1, and d1 from the user for a rectangle R1. Subsequently, read the values a2, b2, c2, and d2 for another rectangle R2. Your task is to determine whether the two rectangles R1 and R2 intersect. To solve this problem, it suffices to check whether both the following conditions are satisfied: * The interval [a1, c1] has an overlap with the interval [a2, c2]. * The interval [b1, d1] has an overlap with the interval [b2, d2]. Two real intervals I = [s,t] and J = [u,v] operlap if and only if I starts before J ends and J starts before I ends, that is, if and only if s <= v and u <= t. Report the output of your program for the following four runs. a1, b1, c1, d1 a2, b2, c2, d2 1, 2, 3, 4 2, 3, 4, 5 1, 2, 3, 4 3, 4, 5, 6 1, 2, 3, 4 4, 5, 6, 7 1, 2, 3, 4 1.5, 5, 2.5, 6

main()
{
    int a,b,c,d,a1,b1,c1,d1;
    printf("enter the value of a1\t=");
    scanf("%d",&a);
    printf("enter the value of b1\t=");
    scanf("%d",&b);
    printf("enter the value of c1\t=");
    scanf("%d",&c);
    printf("enter the value of d1\t=");
    scanf("%d",&d);
    printf("enter the value of a2\t=");
    scanf("%d",&a1);
    printf("enter the value of b2\t=");
    scanf("%d",&b1);
    printf("enter the value of c2\t=");
    scanf("%d",&c1);
    printf("enter the value of d2\t=");
    scanf("%d",&d1);
    if(((a<a1)&(a1<c))&&((b<b1)&(b1<d)))
    {
        printf("***********The given rectangles are overlap each other*************\n");
    }
    else
    {
        printf("*****not overlap*****\n");
    }
}

No comments:

Post a Comment