C++ Program to find the Slope of line

GIVEN: Coordinates of its end points

Here is the c program to find slope of line

#include<iostream>
#include<cmath>
using namespace std;
#define PI 3.14
int slope(int x1,int y1, int x2,int y2)
{
   float tanx,s;
   tanx=(y2-y1)/(x2-x1);
   s=atan(tanx);
   s=(180/PI)*s;
   return s;
}
int main()
{
  float x1,x2,y1,y2,x,tanx,s;
  while(true)
  {
      cout<<"enter the co_ordinate of point A";
      cin>>x1>>y1;
      cout<<"enter the co_ordinate of point B";
      cin>>x2>>y2;
      if(x2-x1==0)
      {
         cout<<"Slope is 90 degrees"<<endl;
         continue;
      }

      else
          s = slope(x1,y1,x2,y2);
      cout<<"slope of line AB"<<s<<"Degrees"<<endl;
  }

}

Leave a Comment