Link to home
Start Free TrialLog in
Avatar of HelpMePls
HelpMePls

asked on

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


ASKER CERTIFIED SOLUTION
Avatar of sa9813
sa9813

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of HelpMePls
HelpMePls

ASKER

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

Expression syntax error !

Thanks
with this I got:

Expression syntax error !

Thanks
#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) ;

}
go with zultis solution...looks perfect. Maybe except for the dx = x2 - x1 part!
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);
}
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);
}
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);
}