Suppose you're asked to write a pair of nested for loops in R to generate a multiplication table. How would you do it?

  • for (i in 1:10) { for (j in 1:10) { print(i * j) } }
  • for (i in 1:10) { for (j in 1:10) { print(i + j) } }
  • for (i in 1:10) { for (j in 1:10) { print(i / j) } }
  • for (i in 1:10) { for (j in 1:10) { print(i - j) } }
To generate a multiplication table using nested for loops in R, you can use the following code: for (i in 1:10) { for (j in 1:10) { print(i * j) } }. It iterates over the values 1 to 10 for both i and j, and within each iteration, calculates and prints the product of i and j.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *