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;
}
Interviews5 answers
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)
5 Answers
Miroslav BuckoPosted Aug 16, 2011, 2:33 AM EDT
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
DMR SantoshPosted Aug 11, 2011, 6:33 PM EDT
Please try to be more specific. The question is not clear....
Pramodh T SPosted Jul 26, 2011, 7:08 AM EDT
Hopefully answered in the forums. See http://www.c-sharpcorner.com/Forums/Thread/131862/how-to-display-oddnumbers-from-a-list-of-numbers0-100.aspx
VulpesPosted Jul 17, 2011, 2:02 AM EDT
i dont know about this one
sureshPosted Jul 16, 2011, 6:53 PM EDT

