Advertisement
nRikee

La patata caliente

Mar 7th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int main()
  6. {
  7.     srand( getpid() );
  8.     int x, num, intentos;
  9.    
  10.     // Inicialización
  11.     printf( "La patata caliente\n\n" );
  12.     x           = 0;
  13.     intentos    = 0;
  14.     num         = (rand() % 100) + 1;   // 0 < num <= 100
  15.    
  16.    
  17.     do {
  18.         printf ( "Introduce un número entre 0 y 100\n" );
  19.         scanf ( "%d" , x );
  20.         intentos++;
  21.         if ( num != x )
  22.             printf ( "El numero es %s que %d\n", ( x>num ? "mayor" : "menor" ), x );
  23.        
  24.     } while ( num != x );
  25.    
  26.     printf ( "Has acertado con %d intentos\n.", intentos );
  27.    
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement