Advertisement
Guest User

Untitled

a guest
Feb 26th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int i,x,n=6;
  8. int T[]={1,2,3,6,8,9};
  9. cout<<"Jakiej liczby szukasz?"<<endl;
  10. cin>>x;
  11. T[n]=x;
  12. i=0;
  13. while(T[i]!=x) i++;
  14. if (i!=n) cout<<"tak";
  15. else cout<<"nie";
  16.  
  17. return 0;
  18. }
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. #include <iostream>
  50.  
  51. using namespace std;
  52.  
  53. int main()
  54. {
  55. int x,l=0,p,n=6,s;
  56. int T[]={1,2,3,4,5,6,7};
  57. p=n-1;
  58. cin>>x;
  59. while(p>=l)
  60. {
  61. s=(l+p)/2;
  62. if (T[s]!=x)
  63.  
  64. if(T[s]<x)
  65. l=s+1;
  66. else p=s-1;
  67. else {cout<<"tak";
  68. break;}
  69. }
  70. if (p<l) cout<<"nie";
  71.  
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement