C++ 程序实现沙漏图案打印
#include
using namespace std;
int main() { int n, m; cin >> n >> m; int k = (sqrt(2 * n + 2.25) - 1.5) / 2; int t = n - (2 * k * k + 2 * k + 1); int cnt = 2 * k + 1; for(int i = k; i >= 1; i --) { for(int j = 0; j < k - i; j ++) cout << ' '; for(int j = 0; j < 2 * i - 1; j ++) cout << (char)m; cout << endl; } for(int i = 2; i <= k; i ++) { for(int j = 0; j < k - i; j ++) cout << ' '; for(int j = 0; j < 2 * i - 1; j ++) cout << (char)m; cout << endl; } cout << t << endl; return 0; }
原文地址: https://www.cveoy.top/t/topic/oNDd 著作权归作者所有。请勿转载和采集!