Suppose you're asked to write a for loop in R that prints the squares of the numbers 1 to 10. How would you do it?

  • for (i in 1:10) { print(i^2) }
  • for (i in 1:10) { print(i * i) }
  • for (i in 1:10) { print(square(i)) }
  • for (i in 1:10) { print(pow(i, 2)) }
To print the squares of the numbers 1 to 10, you can use the for loop for (i in 1:10) { print(i^2) }. It iterates through the values 1 to 10, calculates the square of each value, and prints the result.
Add your answer
Loading...

Leave a comment

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