Home > Back-end >  multiplication Table in dart
multiplication Table in dart

Time:10-28

[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

CodePudding user response:

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

CodePudding user response:

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');
 }
}
  • Related