This sequence represents to each given integer its square.
The limit of the numbers to be squared can be entered by the user.
#include <iostream>
using namespace std;
void squareNumbersAlgorithm(int n) {
int square;
for (int i = 1; i <= n; i++) {
square = i;
square = square * square;
cout << i << ": " << square << endl;
}
}
int main() {
int quantity;
cout << "Up to which number should be squared? ";
cin >> quantity;
squareNumbersAlgorithm(quantity);
return 0;
}
Up to which number should be squared? 10
1: 1
2: 4
3: 9
4: 16
5: 25
6: 36
7: 49
8: 64
9: 81
10: 100