好了,所以我要创建这个钻石形,排序的,它应该是一个菱形但最高右半丢失,矩形的左半边缺失。我有两种形状,但它们没有以菱形形式出现,而是将其中一个打印出来。钻石形状心不是印刷正确
我假设的地方。我必须打印出相同数量的空间以将整个底部形状向右移动?
#include <iostream>
using namespace std;
int main()
{
int row, col, siz;
cout << "Enter the size of the diamond: " << endl;
cin >> siz;
cout << endl << endl;
for(row = 1; row <= siz; row++){
for(col = 1; col <= siz; col ++){
if(col <= siz - row){
cout << " ";
}
else{
cout << "@";
}
}
cout << "\n";
}
for(row = 1; row <= siz; row++){
for(col = row; col <= siz; col++){
cout << "@";
}
cout << "\n";
}
return 0;
}
通过与您的开发环境几乎肯定就应该使这个问题的短期工作的调试器分步执行代码。 – user4581301
您没有分别处理上半部分和下半部分的间距。看到这里http://www.sitesbay.com/cpp-program/cpp-print-diamond-of-star。在发布问题之前,最好在网络上搜索解决方案,您将获得更快的解决方案以及社区不需要搜索解决方案并为您提供链接。你会首先自己动手学习更多。如果还有更多问题,社区随时准备帮助你。在发布这个问题时,你应该展示一些你自己的研究来找到问题的解决方案。 –