C# ile kullanıcı negatif sayı girene kadar girdiği tüm sayıları toplayan ve sonucu ekranda gösteren örnek:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | static void Main(string[] args) { int sayi=0, toplam=0; while(true) { Console.WriteLine("Sayı girin"); sayi=Convert.ToInt32(Console.ReadLine()); if(sayi<0) { break; } toplam+=sayi; } Console.WriteLine("Girilen sayıların toplamı :"+toplam); Console.ReadKey(); } |
Yorum Yap