C# 2-9 arası rakamlara bölünebilen sayılar(combobox)

ilk

sonraki

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{

}

private void Form1_Load(object sender, EventArgs e)
{

comboBox1.Items.Add(“2 ile bölünebilen sayilar”);
comboBox1.Items.Add(“3 ile bölünebilen sayilar”);
comboBox1.Items.Add(“4 ile bölünebilen sayilar”);
comboBox1.Items.Add(“5 ile bölünebilen sayilar”);
comboBox1.Items.Add(“6 ile bölünebilen sayilar”);
comboBox1.Items.Add(“7 ile bölünebilen sayilar”);
comboBox1.Items.Add(“8 ile bölünebilen sayilar”);
comboBox1.Items.Add(“9 ile bölünebilen sayilar”);//combobox’a değerler giriyoruz }

private void button1_Click(object sender, EventArgs e)
{

int a, b, c, d;

a = Convert.ToInt32(textBox1.Text);
b = Convert.ToInt32(textBox2.Text);

listBox1.Items.Clear();
if (comboBox1.Text == “2 ile bölünebilen sayilar”) //Eğer combox’da “2 ile bölünebilen sayılar” seçilmişse..
{
for (c = a; c <= b; c++) //c ilk girilen sayıdan 2. girilen sayıya kadar dönsün..
{

if (c % 2 == 0) //eğer c’nin 2 ye bölümünden kalan “0” ise listboxa c’ yi yaz..
listBox1.Items.Add(c);
}
}
if (comboBox1.Text == “3 ile bölünebilen sayilar”)
{
for (c = a; c <= b; c++)
{

if (c % 3 == 0)
listBox1.Items.Add(c);
}
}
if (comboBox1.Text == “4 ile bölünebilen sayilar”)
{
for (c = a; c <= b; c++)
{

if (c % 4 == 0)
listBox1.Items.Add(c);
}
}
if (comboBox1.Text == “5 ile bölünebilen sayilar”)
{
for (c = a; c <= b; c++)
{

if (c % 5 == 0)
listBox1.Items.Add(c);
}
}

if (comboBox1.Text == “6 ile bölünebilen sayilar”)
{
for (c = a; c <= b; c++)
{

if (c % 6 == 0)
listBox1.Items.Add(c);
}
}

if (comboBox1.Text == “7 ile bölünebilen sayilar”)
{
for (c = a; c <= b; c++)
{

if (c % 7 == 0)
listBox1.Items.Add(c);
}
}
if (comboBox1.Text == “8 ile bölünebilen sayilar”)
{
for (c = a; c <= b; c++)
{

if (c % 8 == 0)
listBox1.Items.Add(c);
}
}

if (comboBox1.Text == “9 ile bölünebilen sayilar”)
{
for (c = a; c <= b; c++)
{

if (c % 9 == 0)
listBox1.Items.Add(c);
}
}
}
}
}

Yazar: Özgüngör Bengü

Bengü Özgüngör sitemizde 3 yazı eklemiş...

Share