Submit Time:2026-04-14 19:58:11
运行 ID: 315892
#include <iostream> #include <string> void printRightAlignedInvertedRightTriangle(int n) { for (int i = 1; i <= n; ++i) { // 计算前置空格数,确保右对齐 std::string line(n - i, ' '); // 追加星号部分 line.append(i, '*'); // 输出整行 std::cout << line << std::endl; } } int main() { int n; std::cout << "Enter the number of rows for the inverted right triangle: "; std::cin >> n; printRightAlignedInvertedRightTriangle(n); return 0; }