Creating Multiplication table using two-dimensional array.
-
יום שני 30 יולי 2012 12:06
i need a program of multiplication table using two-dimensional array.
thanks.
Jes
כל התגובות
-
יום שני 30 יולי 2012 12:34
class Program { static void Main(string[] args) { int[][] numbers = new int[9][]; for (int line = 1; line <=9; line++) { numbers[line-1]=new int[line]; for (int col = 1; col <=line; col++) { numbers[line - 1][col - 1] = line * col; } } for (int line = 1; line <= 9; line++) { for (int col = 1; col <= line; col++) { Console.Write((col + "*" + line + "=" + numbers[line - 1][col - 1]).PadRight(8)); } Console.WriteLine(); } } }
- הוצע כתשובה על-ידי NorkkMicrosoft Community Contributor יום שני 30 יולי 2012 12:37
-
יום שני 30 יולי 2012 13:22
its like this output, but i need the program created in two-dimensional array form
static void Main(string[] args)
{
int prod = 0;
for (int row = 1; row <= 10; row++)
{
for (int col = 1; col <= 10; col++)
{
prod = row * col;
Console.Write(prod + "\t");
}
Console.WriteLine();
}
Console.ReadLine(); -
יום שני 30 יולי 2012 13:31
Hi,
I didnt really understand you. Do you want to have numbers in 2d array, like:
int[,] array2Da = new int[10, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 }, { 9, 10 }, { 11, 12 }, { 13, 14 }, { 15, 16 }, { 17, 18 }, { 19, 20 } }; for (int i = 0; i < array2Da.GetLength(1); i++) { for (int j = 0; j < array2Da.GetLength(0); j++) { Console.WriteLine(string.Format("{0}\t", i * j)); } }
Mitja
-
יום שני 30 יולי 2012 15:53
Hi
filling the table - more or less based on your own code ;-)const int extent = 10; //or 100, or 1000 or ... int[,] multiplicationTable = new int[extent, extent]; for (int x = 1; x < extent + 1; x++) for (int y = 1; y < extent + 1; y++) multiplicationTable[x - 1, y - 1] = x * y;
Result:
1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 8 16 24 32 40 48 56 64 72 80 9 18 27 36 45 54 63 72 81 90 10 20 30 40 50 60 70 80 90 100
Chris
- נערך על-ידי Grecian Developer יום שני 30 יולי 2012 15:55
- נערך על-ידי Grecian Developer יום שני 30 יולי 2012 15:56
- נערך על-ידי Grecian Developer יום שני 30 יולי 2012 15:57
- נערך על-ידי Grecian Developer יום שני 30 יולי 2012 16:02
- נערך על-ידי Grecian Developer יום שני 30 יולי 2012 16:03
- נערך על-ידי Grecian Developer יום שני 30 יולי 2012 16:39
- סומן כתשובה על-ידי jes88 יום שלישי 31 יולי 2012 08:13
-
יום שני 30 יולי 2012 16:07
Hi,
Looks like homework. I always suggest to try this by yourself and ask about a particular point where you are stuck so that you learn something in the process instead of copying/pasting some code.
Have you tried to just declare a two dimensional array ? Where are you stuck ? Else see other responses for a ready to consume solution...
Please always mark whatever response solved your issue so that the thread is properly marked as "Answered".
-
יום שלישי 31 יולי 2012 02:05
Hi ies88:)
Mine is working properly……And you mean two demision instead of two loops.
Plz run my program and it will generate the multipliation table.
-
יום שלישי 31 יולי 2012 02:56