Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. main()
  6. {
  7.     int a=0,b=0,i=0;
  8.     char num[3];
  9.    
  10.     printf("Introduzca un numero del -10 al 10: ");
  11.     gets(num);
  12.  
  13.  
  14.     if(num[0]=='-') {
  15.         a=(num[1]-'0');
  16.         b=(num[2]-'0');
  17.        
  18.         if(num[2]=='\0' && 0<=a && a<10) {         
  19.             i = (num[1]-'0');
  20.         }
  21.         else if(0<=a && a<10 && 0<=b && b<10) {
  22.             i = 10*(num[1]-'0') + (num[2]-'0');
  23.         }
  24.         else {
  25.             printf("El dato introducido no es un número válido.\n");
  26.             getchar();
  27.         }      
  28.     }
  29.     else {
  30.         a=(num[0]-'0');
  31.         b=(num[1]-'0');
  32.        
  33.         if(num[1]=='\0' && 0<=a && a<10) {         
  34.             i = (num[0]-'0');
  35.         }
  36.         else if(0<=a && a<10 && 0<=b && b<10) {
  37.             i = 10*(num[0]-'0') + (num[1]-'0');
  38.         }
  39.         else {
  40.             printf("El dato introducido no es un número válido.\n");
  41.             getchar();
  42.         }      
  43.     }
  44.    
  45.     if(i<=10) {
  46.         printf("El valor introducido es correcto.\n");
  47.     }
  48.     else {
  49.         if(num[0]=='-' && i>10) {
  50.             printf("Se ha introducido un número menor de lo esperado.\n");
  51.         }
  52.         else if(i>10) {
  53.             printf("Se ha introducido un número mayor de lo esperado.\n");
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement