Computer Science, asked by shivanshu8603648185, 2 months ago

Write a program in for loop to print the squares of the first 5 natural numbers . ​

Answers

Answered by profdambaldor
1

Answer:

#include<iostream>  

using namespace std;  

void printSquares(int n)  

{

   int square = 0, prev_x = 0;

   for (int x = 0; x < n; x++)  

   {  

       square = (square + x + prev_x);  

       cout << square << " ";  

       prev_x = x;  

   }  

}

int main()  

{  

  int n = 5;  

  printSquares(n);  

}

Explanation:

Similar questions