Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.  
  10.  
  11. int max = 100;
  12. int min = 0;
  13. int r;
  14. int i = 0;
  15. int middle;
  16.  
  17. srand (time(NULL));
  18.  
  19. r = rand() % (max - min + 1) + min;
  20. cout << "zagadano chislo: " << r << endl;
  21.  
  22. do {
  23. middle = (max + min) / 2;
  24. cout << "(" << max << "+" << min << ")/2 = ";
  25. if (middle > r) {max = middle;}
  26. else if (middle < r) {min = middle;}
  27.  
  28. cout << middle << endl;
  29. cin.get();
  30.  
  31. i++;
  32. } while (middle != r);
  33.  
  34. cout << "popitok: " << i;
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement