Skip to content

Instantly share code, notes, and snippets.

@Roberto24p
Last active March 13, 2020 03:25
Show Gist options
  • Save Roberto24p/35dbe165ecdb28d5bc73e3dd0deff8f3 to your computer and use it in GitHub Desktop.
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).
#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