Mirza
Mirza

Reputation: 3

multiplication Table in dart

[1][I write a simple program in dart to print multiplication table but the output was not I Except][1]

void main{

int num=10;

  for(var i=1;i<=10;++i){
   print('$num*$i=$num');
 }
}

this was my code

Upvotes: -1

Views: 4935

Answers (3)

Saroj Bhandari
Saroj Bhandari

Reputation: 1

void main()
{
 int num =20;
 for(int i=1;i<=10;i++)
  {
    print("num* $i = ${num*i}");
  }
 }

Upvotes: 0

NewbieProgrammer
NewbieProgrammer

Reputation: 142

You forget to add the parenthesis in the main function which acted like a function declaration.

And you also missed to multiply the result of the multiplication by i.

The correct code is :

void main(){

int num=10;

  for(var i=1;i<=10;++i){
   print('$num*$i=${num*i}');
 }
}

instead of this:

void main{

int num=10;

  for(var i=1;i<=10;++i){
   print('$num*$i=$num');
 }
}

Upvotes: 0

Mirza
Mirza

Reputation: 3

Finally I found the answer

var num = 10;
  for (var i = 1; i < 10; i++) {
    print("$num * $i = ${num * i}");
  }

any other ways to print multiplication table in dart using for loop

Upvotes: 0

Related Questions