C# Console For Döngüsü Örnekleri

Spectrum Artz

Web | Graphics
Ultra Member
Katılım
31 Tem 2019
Konular
443
Mesajlar
524
Tepkime puanı
111
Örnek-1: Klavyeden girilen 10 tane sayı arasından pozitif ve aynı zamanda tek olanlarının çarpımlarını hesaplayan ve ekrana yazdıran for örneği.


C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ornek_1
{
    class Program
    {
        static void Main(string[] args)
        {
            int sayi;
            int sonuc = 1;
            for (int i = 1; i <= 10; i++) { Console.WriteLine("{0}.Sayıyı Giriniz;", i); sayi = Convert.ToInt32(Console.ReadLine()); if ((sayi > 0) && (sayi % 2 == 1))
                {
                    sonuc *= sayi;
                }
                Console.WriteLine();
            }
 
            Console.WriteLine("Pozitif ve tek sayıların çarpımı : " + sonuc);
            Console.ReadKey();
        }
    }

}


Örnek-2: Klavyeden girilen cümle şeklindeki bir ifadeyi harf harf alt alta yazdıran for örneği.






C#


Kod:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ornek_2
{
    class Program
    {
        static void Main(string[] args)
        {
            string cumle;
            Console.Write("Bir cümle giriniz: ");
            cumle = Console.ReadLine();
            // bir strin ifadenin karakter sayısını Length
            //Console.WriteLine(cumle.Length);
            for (int i = 0; i < cumle.Length; i++)
            {
                Console.WriteLine(cumle[i]);
            }
            Console.ReadKey();
        }
    }
}
 
Üst