using namespace std; int main() { double x1, x2, y1, y2, d; cin >> x1 >> y1 >> x2 >> y2; d = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)); cout << fixed" /> using namespace std; int main() { double x1, x2, y1, y2, d; cin >> x1 >> y1 >> x2 >> y2; d = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2)); cout << fixed" />

Beecrowd 1015-Distance Between Two Points solution in C,Python

Beecrowd 1015-Distance Between Two Points solution

Solution in C

#include<stdio.h>

int main(){

double x1,x2,y1,y2,d;

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

d=sqrt(pow(x2-x1,2)+pow(y2-y1,2));
printf("%.4lf\n",d);
return 0;

}

Solution in C++

#include <bits/stdc++.h>

using namespace std;

int main() {
    double x1, x2, y1, y2, d;

    cin >> x1 >> y1 >> x2 >> y2;

    d = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
    cout << fixed << setprecision(4) << d << endl;

    return 0;
}

Solution in Python

import math

x1, y1, x2, y2 = map(float, input().split())

d = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
print(f"{d:.4f}")

Next problem: Beecrowd 1016 -Distance solution

2 thoughts on “Beecrowd 1015-Distance Between Two Points solution in C,Python”

Leave a Comment