您的位置:首页 > 其它

How to construct a DiamondOfNumbers

2012-10-06 16:31 120 查看
Like this:

We may use the transform thought to solve this problem



#include <iostream>
using namespace std;

int main()
{
int Num;

cout << "Enter any number in the range of 1 to 9 : ";
cin >> Num;
if(Num >= 1 && Num <= 9)
{
for(int Y=-Num;Y!=Num;Y++)
{
if(Y!=0)
{
for(int X=1;X!=(Y<0?-Y:Y+1);X++)
printf(" ");
for( X=-(Y<0?Num+Y+1:Num-Y);X!=(Y<0?Num+Y+1:Num-Y);X++)
if(X!=0)
printf("%d",(X<0?-X:X+1));
printf("\n");
}
}
}
else
printf("Sorry, limit exceeded. Try again.");

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: