Untitled
unknown
c_cpp
2 years ago
1.3 kB
7
Indexable
#include <iostream>
#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <string>
#include <algorithm>
HANDLE hConsole;
int main()
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
int H = 20;
int W = 20;
int maxLen = (std::to_string(W * H)).length() + 1;
int hLen;
int wLen;
for (int i = 0; i < maxLen; i++) {
std::cout << " ";
}
for (int w = 1; w < W + 1; w++) {
wLen = (std::to_string(w)).length();
for (int i = 0; i < maxLen-wLen; i++) {
std::cout << " ";
}
std::cout << w;
}
std::cout << "\n";
for (int h = 1; h < H + 1; h++) {
hLen = (std::to_string(h)).length();
for (int i = 0; i < maxLen - hLen; i++) {
std::cout << " ";
}
std::cout << h;
for(int factor = 1;factor < W + 1;factor++){
for (int i = 0; i < maxLen - (std::to_string(h * factor)).length(); i++) {
std::cout << " ";
}
if (h == factor) {
std::cout << h * factor;
}
else {
std::cout << h * factor;
}
}
std::cout << "\n";
}
}
Editor is loading...
Leave a Comment