chandra sekhar
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)
By chandra sekhar in ASP.NET on Jul 14 2011
  • Miroslav Bucko
    Aug, 2011 16

    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;
      }

    • 0
  • DMR Santosh
    Aug, 2011 11

    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 

    • 0
  • Pramodh T S
    Jul, 2011 26

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

    • 0
  • Vulpes
    Jul, 2011 17
  • suresh
    Jul, 2011 16

    i dont know about this one

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS