VOOZH about

URL: https://www.geeksforgeeks.org/dsa/program-to-print-first-10-perfect-squares/

⇱ Program to print first 10 perfect squares - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Program to print first 10 perfect squares

Last Updated : 9 Jan, 2024

Write a program to print the first 10 perfect squares. A perfect square is an integer which is the square of some other integer, or we can say that it is a second exponent of an integer

Output format:

1 4 9 16 25 ....

Approach:

We know that the first 10 perfect squares will be square of 1, square of 2, square of 3... till square of 10. So, iterate from 1 to 10 and print squares of each number.

Step-by-step algorithm:

  • Run a loop for i = 1 to 10:
    • For each iteration, calculate sq = i * i
    • Print the square as sq.
  • After 10 iterations, we will have the first 10 perfect squares.

Below is the implementation of the above approach:


Output
1 4 9 16 25 36 49 64 81 100 

Time Complexity: O(1)
Auxiliary Space: O(1)

Comment
Article Tags:
Article Tags: