lundi 2 février 2015

Table with even numbers?

I have code like this to display a table 10 by 10. I want it to display even numbers between 2 and 10 but I can't make it work. This table show numbers from 2 to 11 with even and odd numbers. How can I make it to show even only?


This is what I have now:



int[,] table = new int[10, 10];
Random r1 = new Random();

int num8 = 0;

for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)
{
tabela[i, j] = r1.Next(2,11);
if (table[i, j] ==8)
num8 = num8 + 1;

}
}

for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++)

Console.Write(table[i, j] + " ");
Console.WriteLine();


}


Console.WriteLine("In the table we can find: " + num8 + ", number 8.");


Thanks!





Aucun commentaire:

Enregistrer un commentaire