Guest User

Untitled

a guest
Feb 18th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. /* rand example: guess the number */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <time.h>
  5.  
  6. int main ()
  7. {
  8. int iSecret, iGuess;
  9.  
  10. /* initialize random seed: */
  11. srand ( time(NULL) );
  12.  
  13. /* generate secret number: */
  14. iSecret = rand() % 10 + 1;
  15.  
  16. do {
  17. printf ("Guess the number (1 to 10): ");
  18. scanf ("%d",&iGuess);
  19. if (iSecret<iGuess) puts ("The secret number is lower");
  20. else if (iSecret>iGuess) puts ("The secret number is higher");
  21. } while (iSecret!=iGuess);
  22.  
  23. puts ("Congratulations!");
  24. return 0;
  25. }
Add Comment
Please, Sign In to add comment