Monday, May 27, 2013

Write a method to print out multiplication tables (C#)

Question


Write a method where when you input a number, it prints out a multiplication table of column header times row headers up to the input number. For example, if input = 2, it would write a table with 1 times 1, 1 times 2, 2 times 1 and 2 times 2.

Solution


class Program
{
static void Main ()
{
int input = 10;
if (input <=0)
{
Console.Write("No table");
}
else
{
int[ , ] table = new int[input,input];
 for(int i =0; I < input; i++)
 {
 for (int j =0; j < input; j++)
 {table[i,j] = (i+1) * (j+1);}
}
}
foreach (var i in table)
{
Console.write(i);
Console.Write(Environment.NewLine);
}
}
Console.Readkey();
}



 
 




 

No comments: