12,065,060 members (45,950 online)
Rate this:
See more:
```using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EvenandOdds
{
class Program
{
static void Main(string[] args)
{
List<double> even = new List<double>();
List<double> odd = new List<double>();

Console.Write("odd: ");
Random randomNums = new Random();

for (int i = 0; i < 25; i++) ;
{

Console.WriteLine();

}

}
}
}```

What do I put in that last `WriteLine` to show the odd numbers?
Posted 31-Oct-11 10:23am
Edited 31-Oct-11 10:27am
v3

Rate this:

## Solution 1

Well, you do not check if the number is odd. To do that do something like :

`bool isOdd = num % 2 != 0;`

Use a local variable there and assign the random number to this local. Then you can easily show it using `Console.WriteLine`. Or access the last item using `list[count - 1]`.
v3
André Kraak 31-Oct-11 15:31pm

my 5, took me to long to find the MSDN % operator link.
Nishant Sivakumar 31-Oct-11 15:32pm

Yeah, MSDN is not easy to search huh? :-)
SAKryukov 31-Oct-11 17:24pm

First, one needs to know what is MSDN... My 5 for the answer.
--SA
Rate this:

## Solution 2

You need to check for odd numbers, which you can do with the % operator[^].
```int Num = 5;

if(Num % 2 == 0)
{
// It's even

}
else
{
// It's odd

}```
Nishant Sivakumar 31-Oct-11 15:33pm

Voted 5 as well. We posted at the same time I guess.
André Kraak 31-Oct-11 15:35pm

Thanks.
Member 8349150 31-Oct-11 15:41pm

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EvenandOdds
{
class Program
{
static void Main(string[] args)
{

int random;

List even = new List();
List odd = new List();

Console.Write("odd: ");
Random randomNums = new Random();

for (int randomm = 0; randomm < 25; randomm++)
{

bool isOdd = randomm % 2 != 0;

Console.WriteLine(odd[randomm].ToString());

}
}

}
}

Does not work too well but I tried what you said
SAKryukov 31-Oct-11 17:25pm

...and you did not explain what's "not too well".
--SA
SAKryukov 31-Oct-11 17:25pm

Sure, a 5.
--SA
André Kraak 31-Oct-11 17:39pm

Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 OriginalGriff 160 RDBurmon 100 ppolymorphe 50 CPallini 50 nv3 40
 Dave Kreskowiak 1,857 Richard MacCutchan 1,250 d@nish 980 OriginalGriff 974 CPallini 790

Advertise | Privacy | Mobile
Web01 | 2.8.160204.4 | Last Updated 31 Oct 2011