how to right a simple program to calculate the slope and the distance between 2 points (x1,y1) and (x2,y2)
the slope and the distance beween 2 pointslinear equation program
Page 1 of 1
8 Replies - 18630 Views - Last Post: 01 January 2011 - 01:03 PM
Replies To: the slope and the distance beween 2 points
#2
Re: the slope and the distance beween 2 points
Posted 01 January 2011 - 09:35 AM
#3
Re: the slope and the distance beween 2 points
Posted 01 January 2011 - 10:13 AM
Slope is the change in Y over the change in X. If the change in X is 0, the slope is undefined.
Distance is the square root of the sum of the squares of the change in X and Y.
Now show us your code if you still have problems.
Distance is the square root of the sum of the squares of the change in X and Y.
Now show us your code if you still have problems.
#4
Re: the slope and the distance beween 2 points
Posted 01 January 2011 - 10:36 AM
It is really simple. You can look up the formulas in just about any high school algebra text or google "slope and distance formulas":
delta_x = x2 - x1
delta_y = y2 - y1
slope = delta_y / delta_x
distance = sqrt(delta_x * delta_x + delta_y * delta_y)
writing these in C/C++ is pretty easy.
delta_x = x2 - x1
delta_y = y2 - y1
slope = delta_y / delta_x
distance = sqrt(delta_x * delta_x + delta_y * delta_y)
writing these in C/C++ is pretty easy.
#5
Re: the slope and the distance beween 2 points
Posted 01 January 2011 - 12:08 PM
Its just the Pythagorean theorem and its not too hard to prove/show (if you don't feel like memorizing an another mindless high school equation).






This post has been edited by ImaSexy: 01 January 2011 - 12:09 PM
#6
Re: the slope and the distance beween 2 points
Posted 01 January 2011 - 12:29 PM
ImaSexy, on 01 January 2011 - 02:08 PM, said:
(if you don't feel like memorizing an another mindless high school equation).
Heh, I recently taught it to a 5th grader. I knew he got it when I could give him points from two lines and he could tell me if they intersected! Math isn't hard when you're too young to have been taught to be afraid of it.
#7
Re: the slope and the distance beween 2 points
Posted 01 January 2011 - 12:56 PM
Ive just experienced math teachers that just throw equations at you and they don't have the slightest bit of interest in whether you understand where they came from or not. I think being open minded and having interest in why you do the things you do in mathematics can help you go a long way.
#8
Re: the slope and the distance beween 2 points
Posted 01 January 2011 - 12:59 PM
#include <stdio.h>
#include <math.h>
int slope(float m);
int distance(float len);
int main( void)
{
float x1,x2 ,y1 , y2 ;
printf (“ Enter the two points scale on the two axis X and Y : “) ;
scanf (“%d%d%d%d, & x1, & x2 , & y1 , & y2 ) ;
printf (“The slope for the straight line is : “, slope(m));
printf (“The length between the two points is : “, distance(len));
}
{
int slope (float m)
return m = (x2 – x1 ) / (y2 – y1 ) ;
}
{
Int distance (float len)
Return len = sqrt ((x2 – x1 )* (x2 – x1 )/ (y2 – y1 )* (y2 – y1 ))
}
I do not know where is the problem in this first program
Its just the Pythagorean theorem and its not too hard to prove/show (if you don't feel like memorizing an another mindless high school equation).




[/quote]
#include <math.h>
int slope(float m);
int distance(float len);
int main( void)
{
float x1,x2 ,y1 , y2 ;
printf (“ Enter the two points scale on the two axis X and Y : “) ;
scanf (“%d%d%d%d, & x1, & x2 , & y1 , & y2 ) ;
printf (“The slope for the straight line is : “, slope(m));
printf (“The length between the two points is : “, distance(len));
}
{
int slope (float m)
return m = (x2 – x1 ) / (y2 – y1 ) ;
}
{
Int distance (float len)
Return len = sqrt ((x2 – x1 )* (x2 – x1 )/ (y2 – y1 )* (y2 – y1 ))
}
I do not know where is the problem in this first program
Its just the Pythagorean theorem and its not too hard to prove/show (if you don't feel like memorizing an another mindless high school equation).




[/quote]
This post has been edited by suad1111: 01 January 2011 - 01:01 PM
#9
Re: the slope and the distance beween 2 points
Posted 01 January 2011 - 01:03 PM
this is not how you define a function
look here
http://www.cplusplus...rial/functions/
{
int slope (float m)
return m = (x2 – x1 ) / (y2 – y1 ) ;
}
look here
http://www.cplusplus...rial/functions/
This post has been edited by ImaSexy: 01 January 2011 - 01:04 PM
Page 1 of 1

New Topic/Question
Reply



MultiQuote





|