if–else Kontrol Deyimi Örnekleri

1. Klavyeden girilen bir sayının pozitif mi, negatif mi, 0 mı olduğınu ekrana yazan program.

<br />
&lt;blockquote&gt;&lt;span style=&quot;color: #000000;&quot;&gt;#include &lt;cstdlib&gt;<br />
#include &lt;iostream&gt;&lt;/span&gt;</p>
<p>&lt;span style=&quot;color: #000000;&quot;&gt;using namespace std;&lt;/span&gt;</p>
<p>&lt;span style=&quot;color: #000000;&quot;&gt;int main(int argc, char *argv[])<br />
{<br />
cout &lt;&lt; &quot;Bir sayi giriniz: &quot;;<br />
int sayi;<br />
cin &gt;&gt; sayi;<br />
if(sayi &gt; 0)<br />
cout &lt;&lt; &quot;pozitif\n&quot;;<br />
else if(sayi &lt; 0)<br />
cout &lt;&lt; &quot;negatif\n&quot;;<br />
else if(sayi == 0 )<br />
cout &lt;&lt; &quot;0\n&quot;;<br />
system(&quot;PAUSE&quot;);<br />
return EXIT_SUCCESS;<br />
}&lt;/span&gt;</p>
<p>

2. Kenar uzunlukları girilen üçgenin alanını hesaplayan program.

<br />
&lt;blockquote&gt;&lt;span style=&quot;color: #000000;&quot;&gt;#include &lt;cstdlib&gt;<br />
#include &lt;iostream&gt;<br />
#include &lt;math.h&gt;&lt;/span&gt;</p>
<p>&lt;span style=&quot;color: #000000;&quot;&gt;// #include &lt;math.h&gt; komutu programa matematiksel işlem yapabilme kabiliyeti kazandırır.&lt;/span&gt;</p>
<p>&lt;span style=&quot;color: #000000;&quot;&gt;using namespace std;&lt;/span&gt;</p>
<p>&lt;span style=&quot;color: #000000;&quot;&gt;int main(int argc, char *argv[])<br />
{<br />
cout &lt;&lt; &quot;ucgenin alani icin a, b ve c degerlerini giriniz: &quot; ;<br />
float a, b, c, alan, u;<br />
cin &gt;&gt; a &gt;&gt; b &gt;&gt; c ;<br />
// fabs(x) –&gt; komutu x değerinin mutlak değerini verir<br />
if(a+b&gt;c &amp;&amp; a+c&gt;b &amp;&amp; b+c&gt;a &amp;&amp; fabs(a-b)&lt;c &amp;&amp; fabs(a-c)&lt;b &amp;&amp; fabs(b-c)&lt;a)   // Girirlen değerlerle üçgen oluşuyor mu sorgusu<br />
{<br />
u=(a+b+c)/2;&lt;/span&gt;</p>
<p>&lt;span style=&quot;color: #000000;&quot;&gt;      // sqrt(x) –&gt; komutu x’in karekökünü verir<br />
alan=sqrt(u*(u-a)*(u-b)*(u-c));<br />
cout &lt;&lt;&quot;ucgenin alani: &quot; &lt;&lt; alan &lt;&lt; endl;&lt;/span&gt;</p>
<p>}<br />
else<br />
cout&lt;&lt;&quot;Girdiginiz degerlerle ucgen olusmamaktadir.\n&quot;;</p>
<p>system(&quot;PAUSE&quot;);<br />
return EXIT_SUCCESS;<br />
}</p>
<p>

3. Öğrencinin not ortalaması vizenin %40 ını, finalin de %60 ı toplanarak. Alınan vize ve final notuna göre ortalamasını hesaplayıp;

not 50 den küçük ise T yazan,

not [50,65) aralığında ise C,

not [65, 85) aralığında ise B,

not [85,100] aralığında ise A yazan program.

<br />
&lt;blockquote&gt;&lt;span style=&quot;color: #000000;&quot;&gt;#include &lt;cstdlib&gt;<br />
#include &lt;iostream&gt;&lt;/span&gt;</p>
<p>&lt;span style=&quot;color: #000000;&quot;&gt;using namespace std;&lt;/span&gt;</p>
<p>&lt;span style=&quot;color: #000000;&quot;&gt;int main(int argc, char *argv[])<br />
{<br />
int vize, final;<br />
float ort;<br />
cout &lt;&lt; &quot;vize ve final notlarini girin: &quot;;<br />
cin &gt;&gt; vize &gt;&gt; final;<br />
ort = vize*0.4 + final*0.6;<br />
if(ort &lt; 50)<br />
cout &lt;&lt; &quot;T&quot; &lt;&lt; endl;<br />
else if(50&lt;=ort &amp;&amp; ort &lt;65)<br />
cout &lt;&lt; &quot;C\n&quot;;<br />
else if(65&lt;=ort &amp;&amp; ort &lt;85)<br />
cout &lt;&lt; &quot;B\n&quot;;<br />
else if(85&lt;=ort &amp;&amp; ort &lt;=100)<br />
cout &lt;&lt; &quot;A\n&quot;;<br />
system(&quot;PAUSE&quot;);<br />
return EXIT_SUCCESS;<br />
}&lt;/span&gt;</p>
<p>

 

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: