Thursday 3 July 2014

49).wright a program to find the slope of a line given the coordinates of its end points.

#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;  
  }

}

No comments:

Post a Comment

Write a program which reads a set of integers into an integer array and then prints "YES"if all of them are same otherwise print "NO".

#include<stdio.h> int main() { int a[10],M=0,i,n; printf("enter a value for n\n"); scanf("%d",&n); fo...