09/02/2017

Geeksforgeeks Solution For " Parallel or Perpendicular? "

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 two force vectors, find out whether they are parallel, perpendicular or neither. Let the first vector be A = a1 i +a2 j + a3 k and the second vector be B = b1 i + b2 j + b3 k.

A.B = a1*b1 + a2*b2 + a3*b3

A x B = (a2*b3 - a3*b2) i - (a1*b3 - b1*a3) j + (a1*b2 - a2*b1) k

|A|^2 = a1^2 + a2^2 + a3^2

If A.B = 0, then A and B are perpendicular.

If |A X B|^2 = 0, then A and B are parallel.

Submit Your Solution :- Click Here 


Solution :-

#include <iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       int a1=0,a2=0,a3=0,b1=0,b2=0,b3=0,par,per;
       cin>>a1>>a2>>a3>>b1>>b2>>b3;
       par=(a2*b3-a3*b2)-(a1*b3-b1*a3)+(a1*b2-a2*b1);
       per= a1*b1 + a2*b2 + a3*b3;
       if(par==0)
       cout<<"1\n";
       else if(per==0)
       cout<<"2\n";
       else
       cout<<"0\n";
    }
    return 0;

}


Output:-

Geeksforgeeks Solution For " Parallel or Perpendicular? "

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: