#include <iostream>
#include <math.h>
using namespace std;
struct Ponto{
float x;
float y;
} ;
void LerRetangulo( Ponto ret[ ] , int tam) {
for ( int i = 0 ; i < tam; i++ ) {
cout << "digite coordenadas x e y do ponto " << i + 1 << endl;
cin >> ret[ i] .x >> ret[ i] .y ;
}
}
double CalcDistancia( Ponto ret[ ] , int tam) {
double distancia = 0 ;
for ( int i = 0 ; i < tam; i++ ) {
distancia + = sqrt ( pow ( ret[ i] .x , 2 ) + pow ( ret[ i] .y , 2 ) ) ;
}
return distancia;
}
void imprimir( double distancia, Ponto ret[ ] , int tam) {
for ( int i = 0 ; i < tam; i++ ) {
cout << "Ponto " << i << " = " << ret[ i] .x << ", " << ret[ i] .y << endl;
}
cout << "Distância = " << distancia << endl;
}
int main( int argc, char * argv[ ] ) {
Ponto retangulo[ 4 ] ;
LerRetangulo( retangulo, 4 ) ;
imprimir( CalcDistancia( retangulo, 4 ) , retangulo, 4 ) ;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWF0aC5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKIHN0cnVjdCBQb250b3sKICAgIGZsb2F0IHg7CiAgICBmbG9hdCB5OwogfTsgCnZvaWQgTGVyUmV0YW5ndWxvKFBvbnRvIHJldFtdLCBpbnQgdGFtKSB7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgdGFtOyBpKyspIHsKICAgICAgICBjb3V0IDw8ICJkaWdpdGUgY29vcmRlbmFkYXMgeCBlIHkgIGRvIHBvbnRvICIgPDwgaSArIDEgPDwgZW5kbDsKICAgICAgICBjaW4gPj4gcmV0W2ldLnggPj4gcmV0W2ldLnk7CiAgICB9Cn0KCmRvdWJsZSBDYWxjRGlzdGFuY2lhKFBvbnRvIHJldFtdLCBpbnQgdGFtKSB7CiAgICBkb3VibGUgZGlzdGFuY2lhID0gMDsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCB0YW07IGkrKykgewogICAgICAgIGRpc3RhbmN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