NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

switch - case, if - else if yapısına oldukça benzer bir ifadedir. Ancak aralarında iki fark vardır. Birincisi, switch - case yapısında, aralık değeri girmezsiniz. Direkt olarak ifadelerin bir şeylere eşit olup olmadığına bakarsınız. İkinci farksa, switch - case yapılarında, illa ki uygun koşulun sağlanmasıyla yapının kesilmek zorunda olmayışıdır. 'break' komutu kullanmadığınız takdirde, diğer şartların içindeki işlemleri de yapma imkanınız olabilir. switch case en tepeden başlayarak şartları tek tek kontrol eder. Uygun şart yakalanırsa, bundan sonra ki ifadeleri kontrol etmeden doğru kabul eder. Ve şayet siz break koymamışsanız, eşitlik uygun olsun olmasın, alt tarafta kalan case'lere ait komutlarda çalıştırılacaktır. if - else if ise daha önce söylemiş olduğumuz gibi böyle değildir. Uygun koşul sağlandığında, yapı dışarsına çıkılır.

switch case yapısında ki durumu, aşağıdaki tabloda görebilirsiniz:

switch( degisken ) {
case sabit1:
komut(lar)
[break]
case sabit2:
komut(lar)
[break]
.
.
.
case sabitN:
komut(lar)
[break]
default:
komut(lar);
}

Öğrendiğimiz bilginin pekişmesi için biraz pratik yapalım. Bir not değerlendirme sistemi olsun. 100 - 90 arası A, 89 - 80 arası B, 79 - 70 arası C, 69 - 60 arası D, 59 ve altıysa F olsun. Eğer 100'den büyük veya negatif bir sayı girilirse, o zaman program hatalı bir giriş yapıldığını konusunda bizleri uyarsın. Bunu şimdiye kadar öğrendiğiniz bilgilerle, if - else if yapısını kullanarak rahatlıkla yanıtlayabilirsiniz. Ama şu an konumuz switch case olduğundan, cevabını öyle verelim:

#include<stdio.h>
int main( void )
{
int not;
printf("Lütfen notu giriniz> ");
scanf("%d",¬);
switch( not / 10 ) {
case 10:
case 9: printf("NOT: An"); break;
case 8: printf("NOT: Bn"); break;
case 7: printf("NOT: Cn"); break;
case 6: printf("NOT: Dn"); break;
case 5:
case 4:
case 3:
case 2:
case 1:
case 0: printf("NOT: Fn"); break;
default:
printf("HATA:Yanlş değer girdiniz!n");
}
return 0;
}

Bu sayfadaki kodlar KOPYALANABILIR telefonunuzun ekranina dokunarak kodlari secip kopyalayin!
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.