Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
SL_Dictance challange
#include <iostream> #include <cstdlib> #include <ctime> #include <cmath> using namespace std; int discalc(double x1,double x2 ,double y1,double y2) { return pow(pow(x1-x2,2)+pow(y1-y2,2),0.5); } int main() { double cityX[5],cityY[5]; double distance[10]; srand(time(0)); for (int i=0;i<5;i++) { cityX[i]=(rand()%500)+1; cityY [i]=(rand()%500)+1; } int size(0); for(int i=0;i<5;i++) { for(int j=i+1;j<5;j++) { distance[size]=discalc(cityX[i],cityX[j],cityY [i],cityY[j]); } size++; } double min=discalc(0,500,0,500); double coorX1,coorX2,coorY1,coorY2; for(int i=0;i<10;i++) { if(distance[i]<min) min=distance[i]; coorX1=cityX[i]; coorX2 =cityX[i+1]; coorY1=cityY[i]; coorY2 =cityY[i+1]; cout<<"distance"<<int(min)<<endl; cout <<"city 1 coordinates :"<<int(coorX1)<<','<<int(coorY1)<<endl; cout <<"city 2 coordinates :"<<int(coorX2)<<','<<int(coorY2)<<endl; } return 0; }
run
|
edit
|
history
|
help
0
Big O Notation array problem
w1
Cours C++
kadane's algorithm 2
property get set
Stock buy/sell, maximum subarray problem
const_cast
Addition of two matrix **Part 2
Test 5(2020)
code