#include <iostream>
using namespace std;
int main() {
long int i, number, square = 0;
jump:
cout << "Input a natural number: ";
cin >> number;
if (number <= 0) {
cout << "Input error! Try again"<< endl;
goto jump;
}
for(i = 1; i <= number; i++)
square += i + i - 1;
cout << "The square of number " << number << " is " << square << endl;
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
#include <iostream>
using namespace std;
int main() {
long int i, number, square = 0;
jump:
cout << "Input a natural number: ";
cin >> number;
if (number <= 0) {
cout << "Input error! Try again"<< endl;
goto jump;
}
for(i = 1; i <= number; i++)
square += i + i - 1;
cout << "The square of number " << number << " is " << square << endl;
return 0;
}