fork download
  1. #include <stdio.h>
  2.  
  3. int readInt()
  4. {
  5. int x;
  6. while( !scanf("%d",&x) )
  7. {
  8. char c;
  9. while (( c = getchar()) != '\n' && c != EOF); // limpieza del buffer de entrada
  10. printf("ERROR: No era un numero. Intentalo de nuevo: ");
  11. }
  12.  
  13. return x;
  14. }
  15.  
  16. int main()
  17. {
  18. puts("Introduzca dos nĂºmeros: ");
  19. int x = readInt();
  20. int y = readInt();
  21.  
  22. int z = x + y;
  23. printf("Resultado: %d\n",z);
  24. }
Success #stdin #stdout 0s 10320KB
stdin
1 2
stdout
Introduzca dos números: 
Resultado: 3