Bu �rnekte kullan�c�dan bir ald�ktan sonra 0�dan ba�layarak kullan�c�n�n girdi�i say�ya kadar olan say�lar� toplat�yoruz.Kullan�c�dan ald���m�z bir say�y� ilk �nce de�i�kene atay�p daha sonra for d�ng�s� kullanarak toplam de�i�kenine aktar�p textbox i�ine yazd�r�yoruz.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Girilen_Say�ya_Kadar_Olan_Say�lar�n_Toplam� { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click( object sender, EventArgs e) { int sayi, toplam = 0; // De�i�kenlerimizi belirliyoruz. sayi = Convert.ToInt32(textBox1.Text); // textbox1'e girilen say�y� de�i�kene at�yoruz. for ( int i = 0; i <= sayi; i++) { // Girdi�imiz say�ya kadar d�nen d�ng� olu�turuyoruz. toplam += i; // Say�lar� toplat�yoruz. textBox2.Text = toplam.ToString(); // Sonucu textbox2'ye yazd�r�yoruz. } } } } |
Yorum Gönder