lamont Posted November 13, 2014 Share Posted November 13, 2014 (edited) Arkadaşlar diziye atanan sayının arasındaki çift sayılarını almak istedim sonuç 10 veriyor {1,2,3,4,5,6,7,8,9,10} bu şekilde yaptıgmda yalnış bir sonuç veriyor nerde yalnış yapıyorum for ile normalde çift sayıları toplayabiliyorum ama dizide bir yerde eksigim var nedir arkadaşlar private void button1_Click(object sender, EventArgs e) { int[] sayilar = {10 }; int cifttop = 0; listBox1.Items.Clear(); for (int i = 0; i < sayilar.Length ; i++) { if (sayilar[i] % 2 == 0) { cifttop =cifttop + sayilar[i]; listBox1.Items.Add(cifttop.ToString()); } } } } } Edited November 13, 2014 by lamont Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted November 13, 2014 Editor Share Posted November 13, 2014 Yazdığın kodda dizide sadece 10 var ve doğal olarak 10 yazması normal Quote Link to comment Share on other sites More sharing options...
lamont Posted November 13, 2014 Author Share Posted November 13, 2014 10 nun içindeki sayıların toplamını almak istiyorum {1,2,3,4,5,6,7,8,9,10} bu şekilde yazdıgımda dogru sonucu alamıyorum pairs ? Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted November 13, 2014 Editor Share Posted November 13, 2014 int[] sayilar = {10 }; int cifttop = 0; listBox1.Items.Clear(); for (int i = 0; i < sayilar.Length ; i+=2) { cifttop =cifttop + sayilar[i]; } listBox1.Items.Add(cifttop.ToString()); Hala aynı mantık kurmuyorsun. Quote Link to comment Share on other sites More sharing options...
lamont Posted November 13, 2014 Author Share Posted November 13, 2014 (edited) arkadaşlar çözdüm kafam çok dalgınmış hatamı yeni anladım işte yaptıgım kod private void button1_Click(object sender, EventArgs e) { int[] sayilar = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int cifttop = 0; listBox1.Items.Clear(); for (int i = 0; i < sayilar[0]; i++) { if (sayilar[i] % 2 == 0) { cifttop = cifttop + sayilar[i]; listBox1.Items.Add(cifttop.ToString()); } } } } } } Edited November 14, 2014 by lamont Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted November 13, 2014 Editor Share Posted November 13, 2014 Bu kod gayet doğru çalışıyor sonuç 30 işte. int[] sayilar = {1,2,3,4,5,6,7,8,9,10}; int cifttop = 0; listBox1.Items.Clear(); for (int i = 0; i < sayilar.Length ; i++) { if (sayilar[i] % 2 == 0) { cifttop =cifttop + sayilar[i]; } } listBox1.Items.Add(cifttop.ToString()); listbox a neden ekliyon anlamadım ama ekleyeceksende for dan sonra yaz o kodu. Quote Link to comment Share on other sites More sharing options...
lamont Posted November 14, 2014 Author Share Posted November 14, 2014 evet pairs kodu dogru yazmışım lakin dikkat dagınıklı var bir an önce ögrenme çabası hata yapmama sebeb oluyor 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.