#include <iostream> int main() { int n; std::cout << "Enter a natural number n: "; std::cin >> n; int result = 1; int i = 1; int oddNumber = 1; while (i < n) { oddNumber += 2; result += oddNumber; i++; } std::cout << "The square of " << n << " is: " << result << std::endl; return 0; }
int main() {
int n;
std::cout << "Enter a natural number n: ";
std::cin >> n;
int result = 1;
int i = 1;
int oddNumber = 1;
while (i < n) {
oddNumber += 2;
result += oddNumber;
i++;
}
std::cout << "The square of " << n << " is: " << result << std::endl;
return 0;
}