-
-
Save phaya/ee27e97e2e6508f4f8af to your computer and use it in GitHub Desktop.
¿Por qué en el siguiente programa la conversión a segundos es errónea para 100 años?
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> | |
int main() | |
{ | |
int age; | |
printf("How old are you?\n"); | |
scanf ("%d", &age); | |
printf("You are over %d seconds old\n", age*365*24*60*60); | |
return 0; | |
} |
Vale, creo que sería utilizando %u pues al no tener signo digamos que ampliamos el rango al doble (el de los positivos). No sé si me he explicado.
Tocado y hundido
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
¡Bien! Esa solución funciona y arregla el problema, pero se puede hacer sin tocar el tipo de datos de
age
, y manteniendo la salida del programa como un entero, en vez de unfloat
¿qué otros especificadores de formato se pueden utilizar con números enteros?