• C

# Very Very Very easy question !

Hello
I have no books in C. Could you help me please write the following equation in a c program

x1,x2,y1,y2 are all constants float

D=sqrt((x2-x1)squared +(y2-y1)squared)

print D

Thanks alot
HelpMePls

###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Try,
D = sqrt( pow((x2 - x1), 2 ) + pow((y2-y1), 2));

don't forget to include <math.h>
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
can you give me a complete program that takes arguments from the user for x1,y1,x2,y2 please. I appreciate it alot. Thanks
0
Author Commented:
can you give me a complete program that takes arguments from the user for x1,y1,x2,y2 please. I appreciate it alot. Thanks
0
Author Commented:
with this I got:

Expression syntax error !

Thanks
0
Author Commented:
with this I got:

Expression syntax error !

Thanks
0
Commented:
#include <stdio.h>
#include <math.h>

void main ()
{
double x1,x2,y1,y2, dx, dy, dist ;

printf ("enter first  point x1 y1 : ") ;
scanf  ("%lf%lf",&x1,&y1) ;
printf ("enter second point x2 y2 : ") ;
scanf  ("%lf%lf",&x2,&y2) ;

dx = x2 - x1 ;
dy = y2 - y1 ;

dist = sqrt (dx * dx + dy * dy) ;

printf ("the distance between (%.2f,%.2f) and (%.2f,%.2f) is %.2f \n",x1,y1,x2,y2,dist) ;

}
0
Commented:
go with zultis solution...looks perfect. Maybe except for the dx = x2 - x1 part!
0
Commented:
I am a beginer but trying this program doesn't mean that i am an expert in C language. If i do mistakes please forgive me.
I tried in this way

#include <stdio.h>
#include <math.h>

float ss(float,float,float,float);
main()
{
float x1,x2,y1,y2;
float D;

scanf("%f", &x2);
scanf("%f", &x1);
scanf("%f", &y2);
scanf("%f", &y1);
D = sqrt((x2-x1)*(x2-x1)) + sqrt((y2-y1)*(y2-y1));
printf("\n the summation: %f\n", D);
}
0
Commented:
Please try this small code, i checked with Borland C++ compiler and it worked right.

#include <stdio.h>
#include <math.h>

float ss(float,float,float,float);
main()
{
float x1,x2,y1,y2;
float D;

scanf("%f", &x2);
scanf("%f", &x1);
scanf("%f", &y2);
scanf("%f", &y1);
D = sqrt((x2-x1)*(x2-x1)) + sqrt((y2-y1)*(y2-y1));
printf("\n the summation: %f\n", D);
}
0
Commented:
Please try this small code, i checked with Borland C++ compiler and it worked right.

#include <stdio.h>
#include <math.h>

float ss(float,float,float,float);
main()
{
float x1,x2,y1,y2;
float D;

scanf("%f", &x2);