Last active
March 13, 2020 03:25
-
-
Save Roberto24p/35dbe165ecdb28d5bc73e3dd0deff8f3 to your computer and use it in GitHub Desktop.
Ingresar un número entero y te devuelve lo devuelve invertido (Palíndromo).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <math.h> | |
void invertirNumero(int *); | |
int cantidadDigitos(int ); | |
int main() | |
{ | |
int valor = 0, *punteroV; | |
printf("---Ingresa un valor: "); | |
scanf("%d", &valor); | |
punteroV = &valor; | |
invertirNumero(punteroV); | |
printf("El resultado es: %d\n", *punteroV); | |
} | |
void invertirNumero(int *valor){ | |
int resultado = 0; | |
int dato = *valor, cont = 0, division = *valor, divAux = 0; | |
cont = cantidadDigitos(*valor); | |
do{ | |
divAux = division; | |
dato = divAux%10; | |
division = division/10; | |
resultado = dato*(pow(10, cont-1)) + resultado; | |
printf("La res es--> %d", dato); | |
cont--; | |
}while(cont!=0); | |
*valor = resultado; | |
} | |
int cantidadDigitos(int valor){ //Esta función calcula la cantidad de dígitos que tiene el valor | |
int cont = 0; | |
int val = valor; | |
do{ | |
cont++; | |
val = val/10; | |
}while(val!=0); | |
return cont; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment