using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
Chapter8LINQMultiply
{
class Program
{
static void Main(string[] args)
{
int x1 = 1;
int y1 = 0;
int arraysize = 8;
int start = 1;
int end = arraysize;
int[,]
array = new int[arraysize, arraysize];
int[]
numbers = Enumerable.Range(start,
end - start).ToArray();
//
creates the multiplied list numbers
var multiplied = numbers.SelectMany(
x =>
numbers,
(x, y)
=> x * y);
//converts
the multiplied list of n into an array
int rc = arraysize;
for (rc = 1; rc < arraysize ; rc++)
{
array[rc, 0] = rc;
array[0,
rc] = rc;
}
//Convert
the multiplied list to a 2D array for multiplication table
foreach (int n in multiplied)
{
y1++;
if (y1 >
(arraysize-1))
{
y1 = 1;
x1++;
}
array[x1,
y1] = n;
}
//prints
the array of numbers
int xf;
int yf;
int sf;
for (xf = 0; xf < arraysize; xf++)
{
for (yf = 0; yf < arraysize; yf++)
{
sf = array[xf,yf];
Console.Write(sf.ToString("000")+" ");
}
Console.WriteLine();
}
Console.ReadKey();
}
}
}
Output
000 001 002 003 004 005 006 007
001 001 002 003 004 005 006 007
002 002 004 006 008 010 012 014
003 003 006 009 012 015 018 021
004 004 008 012 016 020 024 028
005 005 010 015 020 025 030 035
006 006 012 018 024 030 036 042
007 007 014 021 028 035 042 049