Square Root in C

0

Follow the code:

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

    int main()
{

     double distancia;
     double x1, y1, x2, y2;

     scanf("%lf %lf ", &x1, &y1);
     scanf("%lf %lf ", &x2, &y2);

     distancia = sqrt (((x2 - x1)*(x2 - x1)) + ((y2 - y1)*(y2 - y1)));

     printf("%.4lf\n", distancia);
     return 0;
}

At the time of running the program, instead of asking for 4 entries as written on the entry, it asks for 5 and the fifth does not interfere with the final value. What is this last entry and why does it occur?

    
asked by anonymous 15.10.2016 / 20:47

2 answers

0

Remove spaces from scanf :

scanf("%lf%lf", &x1, &y1);
    
15.10.2016 / 21:59
0

As mentioned above, just remove the spaces before closing the scanf Here is the code working:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
     double distancia;
     double x1, y1, x2, y2;

     scanf("%lf %lf", &x1, &y1);
     scanf("%lf %lf", &x2, &y2);

     distancia = sqrt(((x2 - x1)*(x2 - x1)) + ((y2 - y1)*(y2 - y1)));

     printf("%.4lf\n", distancia);
     return 0;

    system("PAUSE");
}
    
19.10.2016 / 19:02