今天很高兴,解决了回字型数字输出问题。祥见下文
// Console_test.cpp : Defines the entry point for the console application.
/*本程序主要是输出从1到9个环的“回”字图形
需求按顺序输出从1到9个环的“回”字图形,参见输出。
输出:
1
-------
222
212
222
-------
33333
32223
32123
32223
33333
-------
4444444
4333334
4322234
4321234
4322234
4333334
4444444
-------
555555555
544444445
543333345
543222345
543212345
543222345
543333345
544444445
555555555
-------
66666666666
65555555556
65444444456
65433333456
65432223456
65432123456
65432223456
65433333456
65444444456
65555555556
66666666666
-------
7777777777777
7666666666667
7655555555567
7654444444567
7654333334567
7654322234567
7654321234567
7654322234567
7654333334567
7654444444567
7655555555567
7666666666667
7777777777777
-------
888888888888888
877777777777778
876666666666678
876555555555678
876544444445678
876543333345678
876543222345678
876543212345678
876543222345678
876543333345678
876544444445678
876555555555678
876666666666678
877777777777778
888888888888888
-------
99999999999999999
98888888888888889
98777777777777789
98766666666666789
98765555555556789
98765444444456789
98765433333456789
98765432223456789
98765432123456789
98765432223456789
98765433333456789
98765444444456789
98765555555556789
98766666666666789
98777777777777789
98888888888888889
99999999999999999
-------
*/
#include <cstring>
#include <iostream>
using namespace std;
//#include <string>//在程序中使用串需要有串定义,否则可能莫名其妙出错。
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// The one and only application object
//
void main()
{
void hui(int a);//声明一个无须返回值的函数。
hui(9);//打印回字型9的图形。
}
void hui (int a)
{
int c,m,n;//d,//m为行数,n为列数,输出为M*N回字矩阵,c为行输出基准数,d为列输出基准数。
c=a;//d=a;d不使用。
for(m=1;m<=2*a-1;m++)//行计数//如果写成m<2a-1就会出错,因为电脑不认识2a,只认识2*a
{
for(n=1;n<=2*a-1;n++)//列计数
{
if(n<a-c+1)
{
cout<<a-n+1<<" ";
}
else
{
if (n>a+c-1)//if(n>a-c+1 && n>9)
{
cout<<n+1-a<<" ";
}
else
{
cout<<c<<" ";
}
}
}
cout<<" 行输出基准数c为:"<<c<<endl;//作为数值大小的观察点
if(m<a)
{
c--;
}
else
{
c++;
}
}
}