#include <stdio.h>
// Función para convertir DMS a grados decimales
double dmsToDecimal( int grados, int minutos, double segundos, char direccion) {
double decimal = grados + ( minutos / 60.0 ) + ( segundos / 3600.0 ) ;
if ( direccion == 'S' || direccion == 'W' ) {
decimal = - decimal;
}
return decimal;
}
int main( ) {
// Coordenadas de ejemplo
char direcciones[ ] [ 2 ] = { { 'N' , 'W' } , { 'N' , 'E' } , { 'N' , 'E' } , { 'S' , 'E' } , { 'S' , 'E' } , { 'S' , 'W' } , { 'S' , 'W' } } ;
int coordenadas[ ] [ 4 ] = {
{ 4 , 8 , 54 , 8 } , // N 4° 8' 54.8" W
{ 10 , 15 , 54 , 5 } , // N 10° 15' 54.5" E
{ 26 , 28 , 11 , 8 } , // N 26° 28' 11.8" E
{ 80 , 37 , 0 , 2 } , // S 80° 37' 0.2" E
{ 0 , 0 , 0 , 0 } , // S 0° 0' 0.0" E
{ 70 , 36 , 31 , 9 } , // S 70° 36' 31.9" W
{ 80 , 34 , 47 , 95 } // S 80° 34' 47.95" W
} ;
// Convertir las coordenadas a decimales
for ( int i = 0 ; i < 7 ; i++ ) {
double latitud = dmsToDecimal( coordenadas[ i] [ 0 ] , coordenadas[ i] [ 1 ] , coordenadas[ i] [ 2 ] + coordenadas[ i] [ 3 ] / 100.0 , direcciones[ i] [ 0 ] ) ;
double longitud = dmsToDecimal( coordenadas[ i] [ 2 ] , coordenadas[ i] [ 3 ] , 0 , direcciones[ i] [ 1 ] ) ;
printf ( "Punto %d: Latitud = %.6f, Longitud = %.6f\n " , i
+ 1 , latitud
, longitud
) ; }
return 0 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgovLyBGdW5jacOzbiBwYXJhIGNvbnZlcnRpciBETVMgYSBncmFkb3MgZGVjaW1hbGVzCmRvdWJsZSBkbXNUb0RlY2ltYWwoaW50IGdyYWRvcywgaW50IG1pbnV0b3MsIGRvdWJsZSBzZWd1bmRvcywgY2hhciBkaXJlY2Npb24pIHsKICAgIGRvdWJsZSBkZWNpb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