Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Thursday, 2 June 2016

PROBLEM 11:
Take 8 integer inputs; say X1, Y1, X2, Y2, X3, Y3, X4, Y4. Determine whether these inputs form a rectangle, a square or neither in coordinate plane. Assume that two consecutive inputs form a coordinate point (x, y). If the points form a rectangle or a square then output name of shape with its perimeter.

Sample Input
Sample Output
(0,0) (0,0) (0,0) (0,0)
The points given forms a square with perimeter 0 units
(0,0) (0,4) (4,0) (4,4)
The points given forms a square with perimeter 16 units
(0,0) (4,0) (0,2) (4,2)
The points given forms a rectangle with perimeter 12 units
(0,0) (0,4) (4,2) (0,1)
The points given neither form a square nor a rectangle.
(3,3) (0,0) (6,0) (3,-3)

The points given forms a square with perimeter 12 units

CODE:
#include<stdio.h>
#include<math.h>
int main()
{
//declaration
int x1,y1,x2,y2,x3,y3,x4,y4;
double length1,length2,length3,length4,length5;
double units;
//intilization
x1=0;
y1=0;
x2=0;
y2=0;
x3=0;
y3=0;
x4=0;
y4=0;
length1=0;
length2=0;
length3=0;
length4=0;
length5=0;
units=0;
//working

printf("Enter a X1:");
scanf("%d",&x1);
printf("Enter a Y1:");
scanf("%d",&y1);
printf("Enter a X2:");
scanf("%d",&x2);
    printf("Enter a Y2:");
scanf("%d",&y2);
printf("Enter a X3:");
scanf("%d",&x3);
printf("Enter a Y3:");
scanf("%d",&y3);
printf("Enter a X4:");
scanf("%d",&x4);
printf("Enter a Y4:");
scanf("%d",&y4);
if(x1==0 && y1==0 && x2==0 && y2==0 && x3==0 && y3==0 && x4==0 && y4==0)
{
printf("Its a point, which is both square and rectangle");
}

if(x1==x2)
{
length1=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}
else if(x1==x3)
{
length1=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));
}
else if(x1==x4)
{
length1=sqrt((x4-x1)*(x4-x1)+(y4-y1)*(y4-y1));

}
if(x2==x3)
{
length2=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));

}
else if(x2==x4)
{
length2=sqrt((x4-x2)*(x4-x2)+(y4-y2)*(y4-y2));

}
   else if(x3==x4)
   {
    length2=sqrt((x4-x3)*(x4-x3)+(y4-y3)*(y4-y3));

}
if(y1==y2)
{
length3=sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));

}
else if(y1==y3)
{
length3=sqrt((x3-x1)*(x3-x1)+(y3-y1)*(y3-y1));

}
else if(y1==y4)
{
length3=sqrt((x4-x1)*(x4-x1)+(y4-y1)*(y4-y1));

}
if(y2==y3)
{
length4=sqrt((x3-x2)*(x3-x2)+(y3-y2)*(y3-y2));

}
else if(y2==y4)
{
length4=sqrt((x4-x2)*(x4-x2)+(y4-y2)*(y4-y2));

}
else if(y3==y4)
{
length4=sqrt((x4-x3)*(x4-x3)+(y4-y3)*(y4-y3));

}
if(length1==0||length2==0||length3==0||length4==0)
{
printf("Not rectangle or square");
}
else if(length1==length2 && length2==length3 && length3==length4)
{
printf("Its a square with perimeter");
units=length1+length2+length3+length4;
printf("%lf",units);
}
else if(length1==length2&&length3==length4 || length1==length3&&length2==length4 || length1==length4 && length2==length3)
{
printf("Its a rectangle with perimeter");
units=length1+length2+length3+length4;
printf("%lf",units);
}
return 0;
}
Program Output:


For more problems click here


No comments:

Post a Comment