0–2048 Aralığında Tuttuğunuz Sayıyı Bilgisayara Bulduyoruz

</p>
<p>#include &lt;cstdlib&gt;<br />
#include &lt;iostream&gt;<br />
#include &lt;stdlib.h&gt;<br />
using namespace std;</p>
<p>int main(void)<br />
{<br />
int min = 0, max = 2049, said, num = 0;<br />
cout &lt;&lt; “Bir Sayi Tutun, Ben Bulayim” &lt;&lt; endl;<br />
cout &lt;&lt; “NOT: Sorulara Cevap Verirken ‘E’ (EVET) veya ‘H’ (HAYIR) tuslarini kullanin.” &lt;&lt; endl;<br />
char ans, ans2, ans3;<br />
cout &lt;&lt; “Sayiyi Tuttuunuz mu?”;<br />
cin &gt;&gt; ans3;<br />
while (num != said){<br />
said = (min + max)/2;<br />
cout &lt;&lt; “Tuttugunuz Sayi ” &lt;&lt; said &lt;&lt; “‘ mi?” &lt;&lt; endl;<br />
cin &gt;&gt; ans;<br />
switch (ans){<br />
case ‘E || e’ : cout &lt;&lt; “Tuttugunuz Sayi; ” &lt;&lt; said &lt;&lt; endl;<br />
num = said;<br />
break;<br />
case ‘H || h’ : cout &lt;&lt; “Tuttugunuz Sayi ” &lt;&lt; said &lt;&lt; ” ‘ten Buyuk mu?” &lt;&lt; endl;<br />
cin &gt;&gt; ans2;<br />
switch (ans2) {<br />
case ‘H || h’ : max = said–;<br />
break;<br />
case ‘E || e’ : min = said++;<br />
break;<br />
}<br />
}<br />
}<br />
system(“PAUSE”);<br />
return EXIT_SUCCESS;<br />
}<br />

Yorum Yapın

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑

%d blogcu bunu beğendi: