• 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


HelpMePlsAsked:
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.

sa9813Commented:
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

Your issues matter to us.

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

Start your 7-day free trial
HelpMePlsAuthor 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
HelpMePlsAuthor 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
Redefine Your Security with AI & Machine Learning

The implications of AI and machine learning in cyber security are massive and constantly growing, creating both efficiencies and new challenges across the board. Check out our on-demand webinar to learn more about how AI can help your organization!

HelpMePlsAuthor Commented:
with this I got:

Expression syntax error !

Thanks
0
HelpMePlsAuthor Commented:
with this I got:

Expression syntax error !

Thanks
0
zultiCommented:
#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
sa9813Commented:
go with zultis solution...looks perfect. Maybe except for the dx = x2 - x1 part!
0
DunbujeCommented:
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;

printf("\n please enter x2\n", x2);
 scanf("%f", &x2);
printf("\n please enter x1\n", x1);
scanf("%f", &x1);
printf("\n please enter y2\n", y2);
scanf("%f", &y2);
printf("\n please enter y1\n", y1);
scanf("%f", &y1);
 D = sqrt((x2-x1)*(x2-x1)) + sqrt((y2-y1)*(y2-y1));
 printf("\n the summation: %f\n", D);
}
0
DunbujeCommented:
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;

printf("\n please enter x2\n", x2);
 scanf("%f", &x2);
printf("\n please enter x1\n", x1);
scanf("%f", &x1);
printf("\n please enter y2\n", y2);
scanf("%f", &y2);
printf("\n please enter y1\n", y1);
scanf("%f", &y1);
 D = sqrt((x2-x1)*(x2-x1)) + sqrt((y2-y1)*(y2-y1));
 printf("\n the summation: %f\n", D);
}
0
DunbujeCommented:
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;

printf("\n please enter x2\n", x2);
 scanf("%f", &x2);
printf("\n please enter x1\n", x1);
scanf("%f", &x1);
printf("\n please enter y2\n", y2);
scanf("%f", &y2);
printf("\n please enter y1\n", y1);
scanf("%f", &y1);
 D = sqrt((x2-x1)*(x2-x1)) + sqrt((y2-y1)*(y2-y1));
 printf("\n the summation: %f\n", D);
}
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.