-2

I am a newbie c# user and ı am doing some practice with w3resource.com, it is the question: Write a C# Sharp program that takes a number as input and print its multiplication table: and this is my

Console.WriteLine("Enter a number : ");
int number = Convert.ToInt32(Console.ReadLine());

for (int i = 0; i < 10; i++)
{
  Console.WriteLine("{0} * {1} = {3}", number, i, number * i);

}

and it says to me that the index must be greater than 0...

An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll

(I have translated it from Turkish to English)

sticky bit
  • 36,626
  • 12
  • 31
  • 42
T. Blue
  • 1
  • 1

2 Answers2

1

You have index {3} in the Console.WriteLine method, but you have only 3 arguments. The argument list is zero-based.

Console.WriteLine("{0} * {1} = {3}", number, i, number * i);

It should be

 Console.WriteLine("{0} * {1} = {2}", number, i, number * i);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Anu Viswan
  • 17,797
  • 2
  • 22
  • 51
0
        int i;
        String n;
        Console. Write("Enter any Value for Table Multiplication : ");
        n = Console. ReadiLine();

        int x = Convert.ToInt32(n);
        for (i = 1; i <= 10; i++)
        {
        Console. Write("{0} X {1} = {2} ", x, i, (x *i));
        Console. Read(); }
 
Afreen
  • 23
  • 6
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 24 '23 at 00:39