13/02/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 "

Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: