Advertisement
Guest User

C Random Numbers Game 1

a guest
Oct 27th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. int main(void)
  5. {
  6.  
  7. int yourNumber = 0;
  8. int count = 0;
  9. int subsc = 0;
  10.  
  11. srand(time(NULL));
  12. int r = (random() % 20) + 1;
  13.  
  14. while(yourNumber != r){
  15.  
  16. printf("Sayini gir : ");
  17. scanf("%d",&yourNumber);
  18.  
  19. subsc = abs(yourNumber - r); // farkı buldum.
  20.  
  21. if(subsc <= 4) // fark 4 ise ... desin
  22.         printf("Çok yaklaştın...");
  23.  
  24. count = count + 1;
  25.  
  26. if(yourNumber == r)
  27.     printf("%d kerede bulundu.\n",count);
  28.  
  29. printf("%d\n",r); // bulamiyorum diye sayinin kaç olduğunada bakayım dedim
  30. }
  31.  
  32. return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement