5
Reply

How to display oddnumbers from a list of numbers(0-100) using two combo boxes and a button i.e( if we have two combo boxes placed on the form one containing numbers and then how to display even or odd numbers from a list of these numbers)

chandra sekhar

chandra sekhar

13y
6.9k
0
Reply

    Here is an interesting solution
    //Because all even numbers are divisible by two, we can use the modulo division operator to see if there is any remainder when the
     //number is divided by two. If there is no remainder (it returns zero) then the number is definitely even. Zero is an even number; this
     //method is correct for zero.
     private void button1_Click(object sender, EventArgs e)
      { 
      for (int i = 0; i < 100; i++)
      {
      if (IsEven(i))
      {
      combobox1.Items.Add(i);
      }
      if (IsOdd(i))
      {
      combobox2.Items.Add(i);
      }
      }
      }

      private bool IsOdd(int value)
      {
      return value%2 == 1;
      }

      private bool IsEven(int value)
      {
      return value%2 == 0;
      }

    Hi Chandra sekhar, 


    After creating two comboboxes one for odd and other for even. 
    for (int i = 1; i <= 10; i++)
                {
                    int a, b = 2;
                    a = i % b;
                    if (a = = 0)
                        this.ComboEven.Items.Add(i.ToString());
                    else
                        this.ComboOdd.Items.Add(i.ToString());
                }

    Or if you want to test the entered values you need to save those values in an array and then check each item. in this way you can divide the odds and evens.. 

    Thanks & Regards, 
    Santosh D.M.R 

    Please try to be more specific. The question is not clear....

    i dont know about this one