0
Follow
0
View

【C++】 Solid to hollow diamond

dengluanshun 注册会员
2023-02-27 17:30
< div class = " md_content_show“数据- v - 3967 e397 = " " >

< div class = " aw-list-img " > img

dongsx1989 注册会员
2023-02-27 17:30

Refer to the following:


#include 
#include 
using namespace std;
int main()
{
 char ch;
 int i, j;
 //上半部分
 i = 1;
 while (i <=7) //图形上半部分有 7 行
 { 
     j = 0;
     cout << setw(30 - i);
 
     while (j <=(2 * i - 1)/2) //行的前部分字母
     {
         ch = 'A' + j;
         if (j != 0) 
             cout << ' ';
         else
             cout << ch; 
         j++;
     } 
     while (j < 2 * i - 1) //行的后部分字母
     {
         ch = ch - 1;
         if (ch == 'A')
             cout << ch; 
         else
             cout << ' ';
         j++;
     }
     cout << endl;
     i++;
 }
 //下半部分
 i = 7-1; //图形下半部分有 7-1 行
 while (i>0)
 { 
     j = 0;
     cout << setw(30 - i);
     while (j <= (2 * i - 1) / 2)
     {
         ch = 'A' + j;
         if (j != 0) 
             cout << ' ';
         else
             cout << ch; 
         j++;
     }
     while (j < 2 * i - 1)
     {
         ch = ch - 1;
         if (ch == 'A')
             cout << ch; 
         else
             cout << ' ';
         j++;
     }
     cout << endl;
     i--;
 }
}


About the Author

Question Info

Publish Time
2023-02-27 17:30
Update Time
2023-02-27 17:30

Related Question

从std::vector中获取最后一个元素

使用Hyperscript在提交时清除所有输入字段

Unity、C#脚本集体缩放,各自GameObject变了,间距没变

Jmeter-日志值到CSV文件

为什么我的JavaScript类的方法不能调用邻近的方法?(复制)

Axios + Microsoft Translate API响应中出现奇怪的符号

怎么继续深入学C呢?

如何替换或转换所有的WooCommerce整数

执行js文件问题,execjs问题

scrapy框架的问题