How to construct a DiamondOfNumbers

来源:互联网 发布:考勤软件侵犯隐私 编辑:程序博客网 时间:2024/05/29 09:19

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");}}}elseprintf("Sorry, limit exceeded. Try again.");return 0; }