Skip to content

Instantly share code, notes, and snippets.

@pereslavtsev
Forked from anonymous/gist:8036139
Last active December 31, 2015 20:09
Show Gist options
  • Save pereslavtsev/8038775 to your computer and use it in GitHub Desktop.
Save pereslavtsev/8038775 to your computer and use it in GitHub Desktop.
Задание 2. Ввести координаты трех точек на плоскости, и, напечатать номера тех из них, которые ближе всего находятся друг к другу. Влад
#include "stdafx.h"
#include <iomanip>
#include <iostream>
using namespace std;
const int n=7;
const int m=7;
void zap(int **mas, int n, int m)
{
for (int i=0; i<n; i++)
{
for(int k=0; k<m; k++)
{
mas[i][k]=rand()%9;
}
}
}
void p(int **mas, int n, int m)
{
for (int i=0; i<n; i++)
{
for(int k=0; k<m; k++)
{
cout<<mas[i][k]<<" ";
}
cout<<endl;
}
}
bool result (int **mas, int n, int m)
{
int **kord,z;
cout<<endl<<"Cколько будет точек: "; cin>>z;
kord=new int*[z];
for(int i=0; i<z; i++)
{
kord[i]=new int [2];
}
for(int q=0; q<z; q++)
{
cout<<"Введите координаты x"<<q+1<<": "; cin>>kord[0][q];
cout<<"Введите координаты y"<<q+1<<": "; cin>>kord[1][q];
}
double **rast;
rast=new double*[z];
for(int i=0; i<z; i++)
{
rast[i]=new double[z];
}
for(int i=0; i<z; i++)
{
rast[i][i]=0;
}
double a;
for(int i=0; i<z; i++)
{
for(int k=0; k<z; k++)
{
a=((kord[0][k]-kord[0][i])*(kord[0][k]-kord[0][i]))+((kord[1][k]-kord[1][i])*(kord[1][k]-kord[1][i]));
rast[i][k]=sqrt(a);
}
}
cout<<endl<<endl;
for(int i=0; i<z; i++)
{
for(int k=0; k<z; k++)
{
cout<<rast[i][k]<<" ";
}
cout<<endl;
}
return true;
}
int _tmain(int argc, _TCHAR* argv[])
{
setlocale(LC_ALL, "Rus");
srand(time(0));
int **mas;
mas=new int*[n];
for(int i=0; i<n; i++)
{
mas[i]=new int[m];
}
zap(mas,m,n);
p(mas,m,n);
result(mas,m,n);
system("pause >>null");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment