Sunday, November 21, 2010

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

#include
int check_sides(float w, float x, float y, float z);
float input(float temp);
void check_intersect(float a1, float b1, float c1, float d1,float a2, float b2, float c2, float d2);
int main()
{

float a1,b1,c1,d1;
float a2,b2,c2,d2;


printf("\nEnter first rectangle side values: \n\n");
printf("Enter 'a1' value: ");
a1 = input(a1);

printf("Enter 'b1' value: ");
b1 = input(b1);

printf("Enter 'c1' value: ");
c1 = input(c1);

printf("Enter 'd1' value: ");
d1 = input(d1);

printf("\nEnter second rectangle side values: \n\n");
printf("Enter 'a2' value: ");
a2 = input(a2);

printf("Enter 'b2' value: ");
b2 = input(b2);

printf("Enter 'c2' value: ");
c2 = input(c2);

printf("Enter 'd2' value: ");
d2 = input(d2);


if(check_sides(a1,b1,c1,d1) && check_sides(a2,b2,c2,d2))
{
printf("\n** Four corners of the first rectangle are: ** \n");
printf("(%.1f,%.1f) [bottom left] \n",a1,b1);
printf("(%.1f,%.1f) [bottom right]\n",c1,b1);
printf("(%.1f,%.1f) [top left] \n",a1,d1);
printf("(%.1f,%.1f) [top right] \n",c1,d1);

printf("\n** Four corners of the second rectangle are: ** \n");
printf("(%.1f,%.1f) [bottom left] \n",a2,b2);
printf("(%.1f,%.1f) [bottom right]\n",c2,b2);
printf("(%.1f,%.1f) [top left] \n",a2,d2);
printf("(%.1f,%.1f) [top right] \n",c2,d2);

check_intersect(a1,b1,c1,d1,a2,b2,c2,d2);

}
else
printf("Invalid sides\n");

}
void check_intersect(float a1, float b1, float c1, float d1,float a2, float b2, float c2, float d2)
{
if((a1 <= c2 && a2 <= c1) || (b1 <= d2 && b2 <= d1))
{
printf("\nR1 and R2 rectangles are intersect \n");
}
else
printf("\nR1 and R2 rectangles aren't intersect \n");
}

float input(float temp)
{
scanf("%f",&temp);
return temp;
}
int check_sides(float w, float x, float y, float z)
{
int a;
a = (w <= y && x <= z) ? 1: 0;
return a;
}