Николай Веселуха
Высший разум
(359331)
1 год назад
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
unsigned parse_unsigned(const char* msg) {
cout << msg;
unsigned value;
cin >> value;
return value;
}
string result_line(const unsigned n) {
const auto m = static_cast<unsigned long long>(n);
const auto width = static_cast<size_t>(log10(n * n)) + 1;
const auto max_width = width + width % 4;
string token;
string result;
for (auto i = 0ULL; i < m; ++i) {
token = to_string(i * i);
result += string(max_width - token.length(), ' ') + token;
}
return result;
}
int main() {
auto n = parse_unsigned("N: ");
cout << result_line(n);
}
Ксения РайтГений (84667)
1 год назад
С чего это Вы вдруг решили, что надо выводить квадраты целых чисел от нуля до N-1 ? Очередной косяк у Вас:
Создать код на языке C++