O
The program works properly if I declare the "distance" function as int but I want to declare it as float because there are certain distances that are with decimals.Just change the declaration to float.1.- Variables resultadoX and resultadoY must be changed to float.2.- Them arrays Tpunto1 and Tpunto2 must also be of type float, elements will be floating.3.- Values that return functions distancia, distanciaX and distanciaY They'll be type float, therefore, we must change the kind of value that returns these functions to float.4.- In the first parameter of the function scanf instead of using the specifyer %i, we must use %f (since this tells you scanf He's gonna read a type data float).5.- Each time you define a function, you must specify the type of data that will have each parameter. In the code you proposed, you don't. 6.- The prototypes of each function are missing, otherwise the compiler will invent the statement and this generates undefined behavior (the function may not return the expected value in time of execution).With the above changes, the code would remain:#include <math.h>
#include <stdio.h>
float distancia (float, float);
float distanciaX (float, float);
float distanciaY(float, float);
//Según el estándar la función main debe retornar un valor
int main()
{
float Tpunto1[2], Tpunto2[2], resultadoX, resultadoY, resultadoDist;
printf("ingresar x1: ");
scanf("%f", &Tpunto1[0]);
printf("ingresar y1: ");
scanf("%f", &Tpunto1[1]);
printf("ingresar x2: ");
scanf("%f", &Tpunto2[0]);
printf("ingresar y2: ");
scanf("%f", &Tpunto2[1]);
resultadoX = distanciaX(Tpunto1[0], Tpunto2[0]);
resultadoY = distanciaY(Tpunto1[1], Tpunto2[1]);
resultadoDist = distancia(resultadoX,resultadoY);
printf("La distancia entre ambos puntos es de: %f", resultadoDist);
return 0;
}
float distancia (float distX, float distY)
{
float resultadoDist;
resultadoDist = sqrt(distX + distY);
return resultadoDist;
}
float distanciaX (float x1, float x2)
{
float resultadoX;
resultadoX = pow(x2-x1, 2);
//distanciaY = pow(Tpunto2.y2-Tpunto1.y1),2)
//distancia = sqrt(pow((Tpunto2.x2-Tpunto1.x1),2)+(pow(Tpunto2.y2-Tpunto1.y1),2));
return resultadoX;
}
float distanciaY(float y1, float y2)
{
float resultadoY;
resultadoY = pow(y2-y1,2);
return resultadoY;
}