1015 - Distância Entre Dois Pontos
Aplicação direta da fórmula de distância euclidiana.
Descrição
Solução
Aplicação direta da fórmula apresentada no enunciado. Para a maioria das linguagens, é necessário recorrer a uma biblioteca externa para usar a operação da raiz quadrada.
#include <stdio.h>
#include <math.h>
int main(){
double x1, y1, x2, y2, distancia;
scanf("%lf %lf\n%lf %lf", &x1, &y1, &x2, &y2);
distancia = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
printf("%.4lf\n", distancia);
return 0;
}#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int main(){
double x1, y1, x2, y2, distancia;
cin >> x1 >> y1 >> x2 >> y2;
distancia = sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
cout << setprecision(4) << fixed << distancia << endl;
return 0;
}let input = require("fs").readFileSync("/dev/stdin", "utf8");
let lines = input.split("\n");
let [x1, y1] = lines.shift().split(" ").map((x) => parseFloat(x));
let [x2, y2] = lines.shift().split(" ").map((x) => parseFloat(x));
let distancia = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
console.log(distancia.toFixed(4));import math
x1, y1 = [float(x) for x in input().split(' ')]
x2, y2 = [float(x) for x in input().split(' ')]
distancia = math.sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1))
print(f"{distancia:.4f}")Last updated
Was this helpful?