Monday, 13 February 2017

Geeksforgeeks Solution For " Check if given four points form a square "

GeeksforGeeks Solution For School Domain .Below You Can Find The Solution Of Basic ,Easy ,Medium ,Hard .You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Given coordinates of four points in a plane, find if the four points form a square or not.

Submit Your Solution :- Click Here 


Solution :-

#include <iostream>
#include<math.h>
using namespace std;

int main() 
{
int t,x1,x2,x3,x4,y1,y2,y3,y4;
double r,d1,d2,d3,d4,d5,d6;
r=sqrt(2);
cin>>t;
while(t--)
{
   cin>>x1>>y1>>x2>>y2>>x3>>y3;
        d1=sqrt(((x2-x1)*(x2-x1))+((y2-y1)*(y2-y1)));
        d2=sqrt(((x3-x2)*(x3-x2))+((y3-y2)*(y3-y2)));
        d3=sqrt(((x4-x3)*(x3-x3))+((y4-y3)*(y4-y3)));
        d4=sqrt(((x1-x4)*(x1-x4))+((y1-y4)*(y1-y4)));
        //d5 d6 are diagonal
        d5=sqrt(((x3-x1)*(x3-x1))+((y3-y1)*(y3-y1)));
        d6=sqrt(((x4-x2)*(x4-x2))+((y4-y2)*(y4-y2)));
       
        if((d1==d2)&&(d2==d3)&&(d3==d4)&&(d4==d1)&&(d5==d6))
            cout<<"1"<<endl;
        else
            cout<<"0"<<endl;
}
return 0;
}



Output:-

Geeksforgeeks Solution For " Check if given four points form a square "

No comments:
Write comments

Recommended Posts × +