C# C# Collections Arrays Multidimensional Arrays

can't solve callenge 1 of 1

Challenge Task 1 of 1

Return a multiplication table consisting of a 2D multidimensional array. The table should contain all of the products of integers from 0 to maxFactor. For example, if maxFactor is 3 the resulting multiplication table should contain the following: 0 0 0 0 0 1 2 3 0 2 4 6 0 3 6 9

Bummer! Your code could not be compiled. Please click on "Preview" to view the compiler errors. Restart Preview Get Help Recheck work Math.cs

array 1 namespace Treehouse.CodeChallenges 2 { 3 public static class MathHelpers 4 { 5 public static int[,] BuildMultiplicationTable(int maxFactor) 6 { 7 for (int i = 0; i < array.Length; i++) 8 { 9 System.Console.Write("maxFactor({0}): ", i); 10 } 11 ​ 12 ​ 13 } 14 } 15 } 16 ​

Math.cs
namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
        public static int[,] BuildMultiplicationTable(int maxFactor)
        {
            for (int i = 0; i <  array.Length; i++)
        {
            System.Console.Write("maxFactor({0}): ", i);
        }


        }
    }
}

2 Answers

Steven Parker
Steven Parker
172,268 Points

Here's a few hints:

  • you don't need to write to the console, just build and return the table.
  • you might need a second loop nested inside the first to handle both dimensions.
  • it's a multiplication table — don't forget to multiply.
HIDAYATULLAH ARGHANDABI
HIDAYATULLAH ARGHANDABI
20,984 Points

Pay attention you need to write the using directives properly

using System.Collections.Generic;
using System;
namespace Treehouse.CodeChallenges
{
    public static class MathHelpers
    {
         public static List <int> GetPowersOf2 (int UpperLimit)
        {

            var PowersOf2List = new List <int> ();

            for (int index = 0; index < UpperLimit + 1; index++)
            {
                PowersOf2List.Add ( (int) Math.Pow (2, index) );
            }
            return PowersOf2List;
        }
    }
}