C# Console If Else Örnekleri - Bilişim Konuları

C# Console If Else Örnekleri

Örnek1: Klavyeden girilen vize ve final notuna göre vize notunun %40 ve final notunun %60 ını alarak ortalamayı hesaplayan ortalama 50 ve üzerinde ise dersten geçtiniz değilse dersten kaldınız yazdıran program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int vize, final;
            double ort;
            Console.Write("1.Notu Girin:");
            vize = Convert.ToInt32(Console.ReadLine());
            Console.Write("2.Notu Girin:");
            final = Convert.ToInt32(Console.ReadLine());
            ort = (vize * 40 / 100) + (final * 60 / 100);
            if (ort >= 50)
                Console.WriteLine("Ortalamanız {0} dersten geçtiniz.", ort);
            else
                Console.WriteLine("Ortalamanız {0} dersten kaldınız.", ort);

            Console.ReadKey();
        }
    }
}

Örnek2: Kullanıcıdan şifre ve kullanıcı adını isteyerek bunları kontrol eden doğru girildiğinde doğru girildiğinde doğru giriş, yanlış girildiğinde yanlış giriş şeklinde mesaj veren program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_2
{
    class Program
    {
        static void Main(string[] args)
        {
            string kadi, sifre;
            Console.Write("Kullanıcı adını girin:");
            kadi = Console.ReadLine();
            Console.WriteLine("Şifrenizi girin:");
            sifre = Console.ReadLine();
            if (kadi == "admin" && sifre == "1234")
                Console.WriteLine("Giriş işlemi başarılı.");
            else
                Console.WriteLine("Girdiğiniz kullanıcı adı veya şifre hatalı");

            Console.ReadKey();
        }
    }
}

Örnek3: Klavyeden girilen bir sayının pozitif sayı olup olmadığını kontrol eden program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Bir sayı giriniz:");
            int sayi = Convert.ToInt32(Console.ReadLine());
            if (sayi % 2 == 0)
                Console.WriteLine("Girdiğiniz sayı çifttir.");
            else
                Console.WriteLine("Girdiğiniz sayı tektir.");

            Console.ReadKey();
        }
    }
}

Örnek4: Klavyeden girilen bir sayının tek sayımı yoksa çift sayı mı olduğunu bulan program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_4
{
    class Program
    {
        static void Main(string[] args)
        {
            int vize, final;
            double ort;
            Console.Write("1.Notu Girin:");
            vize = Convert.ToInt32(Console.ReadLine());
            Console.Write("2.Notu Girin:");
            final = Convert.ToInt32(Console.ReadLine());
            ort = (vize * 40 / 100) + (final * 60 / 100);
            if (ort >= 50)
                Console.WriteLine("Ortalamanız {0} dersten geçtiniz.", ort);
            else
                Console.WriteLine("Ortalamanız {0} dersten kaldınız.", ort);

            Console.ReadKey();
        }
    }
}

Örnek5: Klavyeden girilen bir harfe göre dört işlem yapan program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_5
{
    class Program
    {
        static void Main(string[] args)
        {
            double sayi1, sayi2, sonuc = 0;
            Console.Write("Birinci sayıyı girin:");
            sayi1 = Convert.ToDouble(Console.ReadLine());
            Console.Write("İkinci sayıyı girin:");
            sayi2 = Convert.ToDouble(Console.ReadLine());
            Console.WriteLine("Toplama için---> t \n Çıkarma için---> ç \n Çarpma için---> x \n Bölme için---> b tuşuna basınız.");
            string islem = Console.ReadLine();
            if (islem == "t")
                sonuc = sayi1 + sayi2;
            else if (islem == "ç")
                sonuc = sayi1 - sayi2;
            else if (islem == "x")
                sonuc = sayi1 * sayi2;
            else if (islem == "b")
                sonuc = sayi1 / sayi2;
            else
                Console.WriteLine("Yanlış bir tuşa bastınız.");
            Console.WriteLine("İşlemin Sonucu:" + sonuc);

            Console.ReadKey();
        }
    }
}

Örnek6: Klavyeden girilen ürün miktarına göre indirim yaparak toplam tutarı hesaplayan program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_6
{
    class Program
    {
        static void Main(string[] args)
        {
            double urun1, urun2, ilktoplam, odemetutari, indirim;
            Console.Write("Birinci ürünün fiyatını girin:");
            urun1 = Convert.ToDouble(Console.ReadLine());
            Console.Write("İkinci ürünün fiyatını girin:");
            urun2 = Convert.ToDouble(Console.ReadLine());
            ilktoplam = urun1 + urun2;
            odemetutari = ilktoplam;
            if (ilktoplam >= 200)
            {
                indirim = urun2 * 25 / 100;
                odemetutari = ilktoplam - indirim;
            }
            Console.WriteLine("Ödeme tutarı:" + odemetutari);

            Console.ReadKey();
        }
    }
}

Örnek7: Klavyeden girilen bir sayının çift sayımı yoksa tek sayı mı olduğunu bulan program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_7
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Sayı : ");
            int sayi = Convert.ToInt32(Console.ReadLine());
            if (sayi % 2 == 0)//Girilen sayı çiftse
            {
                Console.WriteLine("Girdiğiniz sayı çift.");
            }
            else
            {
                Console.WriteLine("Girdiğiniz sayı tek.");
            }
            Console.ReadKey();
        }
    }
}

Örnek8: Klavyeden girilen final ve vize notuna göre sonucu hesaplayan ve geçip geçmediğini bulan program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_8
{
    class Program
    {
        static void Main(string[] args)
        {
            int vize, final;
            double ort;
            Console.Write("1.Notu Girin:");
            vize = Convert.ToInt32(Console.ReadLine());
            Console.Write("2.Notu Girin:");
            final = Convert.ToInt32(Console.ReadLine());
            ort = (vize * 40 / 100) + (final * 60 / 100);
            if (ort >= 50)
                Console.WriteLine("Ortalamanız {0} dersten geçtiniz.", ort);
            else
                Console.WriteLine("Ortalamanız {0} dersten kaldınız.", ort);

            Console.ReadKey();
        }
    }
}

Örnek9: Klavyeden girilen kullanıcı adı ve şifreye göre doğru giriş yapılıp yapılmadığını kontrol eden program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_9
{
    class Program
    {
        static void Main(string[] args)
        {
            string kadi, sifre;
            Console.Write("Kullanıcı adını girin:");
            kadi = Console.ReadLine();
            Console.WriteLine("Şifrenizi girin:");
            sifre = Console.ReadLine();
            if (kadi == "admin" && sifre == "1234")
                Console.WriteLine("Giriş işlemi başarılı.");
            else
                Console.WriteLine("Girdiğiniz kullanıcı adı veya şifre hatalı");

            Console.ReadKey();
        }
    }
}

Örnek10: Kullanıcının girmiş olduğu bir sayının tek sayı mı çift sayı mı olduğunu bulan program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_10
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Bir sayı giriniz:");
            int sayi = Convert.ToInt32(Console.ReadLine());
            if (sayi % 2 == 0)
                Console.WriteLine("Girdiğiniz sayı çifttir.");
            else
                Console.WriteLine("Girdiğiniz sayı tektir.");

            Console.ReadKey();
        }
    }
}

Örnek11: Klavyeden girilen sayının pozitif, negatif yada sıfır olduğunu bulan program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_11
{
    class Program
    {
        static void Main(string[] args)
        {
            int sayi;
            Console.Write("Lütfen bir sayı girin:");
            sayi = Convert.ToInt32(Console.ReadLine());
            if (sayi > 0)
                Console.WriteLine("{0} sayısı pozitif bir sayıdır.", sayi);
            else if (sayi < 0)
                Console.WriteLine("{0} sayısı negatif bir sayıdır.", sayi);
            else
                Console.WriteLine("Girilen sayı 0'a eşittir.");

            Console.ReadKey();
        }
    }
}

Örnek12: Klavyeden girilen su sıcaklığına göre suyun katı, sıvı yada gaz halinde bulunduğunu bulan program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_12
{
    class Program
    {
        static void Main(string[] args)
        {
            double sicaklik;
            Console.WriteLine("Maddenin sıcaklık değerini giriniz.");
            sicaklik = Convert.ToDouble(Console.ReadLine());

            if (sicaklik >= 100)
            {
                Console.WriteLine("Madde {0} derecede gaz haldedir.", sicaklik);
            }
            else if (sicaklik > 0)
            {
                Console.WriteLine("Madde {0} derecede sıvı haldedir.", sicaklik);
            }
            else
            {
                Console.WriteLine("Madde {0} derecede katı haldedir.", sicaklik);
            }
            Console.ReadKey();
        }
    }
}

Örnek13: Klavyeden girilen üç sınav notuna göre ortalamayı hesaplayıp geçti kaldı şeklinde ekrana yazdıran program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_13
{
    class Program
    {
        static void Main(string[] args)
        {
            int s1, s2, s3;
            double ort;

            Console.WriteLine("1. sınav notunu giriniz.");
            s1 = Convert.ToInt16(Console.ReadLine());
            Console.WriteLine("2. sınav notunu giriniz.");
            s2 = Convert.ToInt16(Console.ReadLine());
            Console.WriteLine("3. sınav notunu giriniz.");
            s3 = Convert.ToInt16(Console.ReadLine());

            ort = (s1 + s2 + s3) / 3;

            if (ort >= 50)
            {
                Console.WriteLine("Geçti");
            }
            else
            {
                Console.WriteLine("Kaldı");
            }
            Console.ReadKey();
        }
    }
}

Örnek14: Kullanıcıdan istediği bir sayının tek sayı olup olmadığını kontrol eden program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_14
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Sayı : ");
            int sayi = Convert.ToInt32(Console.ReadLine());
            if (sayi % 2 == 0)//Girilen sayı çiftse
            {
                Console.WriteLine("Girdiğiniz sayı çift.");
            }
            else
            {
                Console.WriteLine("Girdiğiniz sayı tek.");
            }
            Console.ReadKey();
        }
    }
}

Örnek15: Klavyeden girilen iki sayının birbirine tam olarak bölünüp bölünmediğini bulan program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_15
{
    class Program
    {
        static void Main(string[] args)
        {
            int sayi1, sayi2, kalan;
            Console.Write("1. Sayıyı Girin : ");
            sayi1 = Convert.ToInt32(Console.ReadLine());
            Console.Write("2. Sayıyı Girin : ");
            sayi2 = Convert.ToInt32(Console.ReadLine());
            kalan = sayi1 % sayi2;

            if (kalan == 0)
            {
                Console.WriteLine("{0} sayısı {1} sayısına tam bölünüyor.", sayi1, sayi2);
            }
            else
            {
                Console.WriteLine("{0} sayısı {1} sayısına tam bölünmüyor. Kalan {2}. ", sayi1, sayi2, kalan);
            }
            Console.ReadKey();
        }
    }
}

Örnek16: Klavyeden girilen bir sayının karesini, küpünü ve karekökünü seçilen rakama göre hesaplayan ve ekrana yazdıran program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_16
{
    class Program
    {
        static void Main(string[] args)
        {
            int x, secim;
            double kare, kok, kup;
            Console.Write("Bir sayı giriniz=");
            x = int.Parse(Console.ReadLine());
            Console.Write("1-Kare 2-Küp 3-Kök\n");
            Console.WriteLine();
            Console.Write("Seçiminiz= ");
            secim = int.Parse(Console.ReadLine());
            if (secim == 1)
            {
                kare = x * x;
                Console.Write("Girdiğiniz sayının karesi= {0}", kare);
            }
            else if (secim == 2)
            {
                kup = x * x * x;
                Console.Write("Girdiğiniz sayının kübü= {0}", kup);
            }
            else if (secim == 3)
            {
                kok = Math.Sqrt(x);
                Console.Write("Girdiğiniz sayının kökü= {0}", kok);
            }
            Console.ReadKey();
        }
    }
}

Örnek17: Klavyeden girilen bir sayının sıfır mı yoksa negatif mi yoksa pozitif mi olduğunu bulan program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_17
{
    class Program
    {
        static void Main(string[] args)
        {
            int sayi;
            Console.Write("Bir sayı giriniz=");
            sayi = int.Parse(Console.ReadLine());

            if (sayi < 0)
            {
                Console.Write("Girdiğiniz Sayı Negatif");
            }
            else if (sayi > 0)
            {
                Console.Write("Girdiğiniz Sayı Pozitif");
            }
            else
            {
                Console.Write("Girdiğiniz Sayı Sıfır");
            }
            Console.ReadKey();
        }
    }
}

Örnek18: Klavyeden girilen iki sayıyı karşılaştırarak hangisinin büyük olduğunu yada eşit olup olmadıklarını kontrol eden program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_18
{
    class Program
    {
        static void Main(string[] args)
        {
            int sayi1, sayi2;
            sayi1 = Convert.ToInt32(Console.ReadLine());
            sayi2 = Convert.ToInt32(Console.ReadLine());
            if (sayi1 > sayi2)
            {
                Console.WriteLine("1. Sayı Büyük");
            }
            else if (sayi2 > sayi1)
            {
                Console.WriteLine("2. Sayı Büyük");
            }
            else
            {
                Console.WriteLine("Sayılar Eşit");
            }
            Console.ReadKey();
        }
    }
}

Örnek19: Klavyeden girilen sayının pozitif sayı olup olmadığını kontrol eden program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_19
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Sayı giriniz: ");
            int a = int.Parse(Console.ReadLine());

            if (a < 0)
            {
                Console.WriteLine("Pozitif bir sayı giriniz.");
            }

            Console.ReadKey();
        }
    }
}

Örnek20: Klavyeden girilen bir sayının negatif sayı olup olmadığını kontrol eden program.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace örnek_20
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Sayı giriniz: ");
            int a = int.Parse(Console.ReadLine());

            if (a > 0)
                Console.WriteLine("Negatif bir sayı giriniz.");

            Console.ReadKey();
        }
    }
}
Bu Yazıya Tepkin Nedir?
+1
0
+1
0
+1
1
+1
0
+1
0
+1
0
+1
4

<< Önceki Yazı

Yorum Yap

1 Yorum