C# | While Döngüsü Örnekleri

1

1Picasso

Confirmed Memb.
Joined
Nov 20, 2019
Messages
88
Reaction score
12
Örnek: Basit bir toplama örneği
C#:
int toplam = 0;
int i = 0;

while (i < 100)
{
    toplam += i;
    i++;
}
Console.WriteLine(toplam);

Örnek: Sayının basamak sayısını bulma örneği

C#:
int sayi = Convert.ToInt32(Console.ReadLine());
int basamak = 0;

while (sayi > 0)
{
    basamak++;
    sayi = sayi / 10;
}

Console.WriteLine("Girdiğiniz sayı " + basamak.ToString() + "basamaklıdır.");

Örnek : 0 ile 100 arasındaki tek sayıları toplayarak sonucu ekranda gösteren program

C#:
int sayi = 0;
int toplam = 0;
while (sayi<=100)
{
     if (sayi % 2 == 1)
        toplam += sayi;      
    sayi++;
}
Console.WriteLine("Tek sayıların toplamı:" + toplam);
Console.ReadKey();
 
SPAM IS FORBIDDEN!
  • SPAMMERS ARE BANNED FROM THE FORUM AND CANNOT USE ANY OF THE CHEATS
  • For example: thanks, thx, very good, asdqwe, working, ty and so on!
  • For example: Writing the same message over and over. thanks, thx and so on!
  • Copying and copying someone else's message is prohibited.
  • It is forbidden to send messages to increase the number of comments on threads that you have no knowledge of.
  • Write your own opinion when commenting!
  • If you see spam message, please let us know with the REPORT button!

Tema düzenleyici

Top Bottom