lamont Posted October 3, 2014 Share Posted October 3, 2014 C# arkadaşlar aşagıdaki kodda textbox girilen çift sayıların toplamını label1 tek sayıların aralarındaki toplamı label2 yazdırmak için aşagıdaki kodu yazdım ama program yalnış topluyor degişkenlere 1 de verdim i=0 başlattım 1 den de başalttım sonuç aynı yalnış sonuç veriyor hata nedir anlaymadım ? private void button1_Click(object sender, EventArgs e) { int sayi, tek = 0, cif=0; sayi = int.Parse(textBox1.Text); for (int i = 1; i <= sayi; i++) if (i % 2 == 0) cif += i; else { label1.Text = cif.ToString(); tek += i; label2.Text = tek.ToString(); } } } } Quote Link to comment Share on other sites More sharing options...
destroychip Posted October 3, 2014 Share Posted October 3, 2014 label.text leri döngünün dışında yazdırmalısın Quote Link to comment Share on other sites More sharing options...
lamont Posted October 3, 2014 Author Share Posted October 3, 2014 (edited) evet döngünün dışında olması gerekiyormuş tşk ederim kardeş Edited October 3, 2014 by lamont Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.