今天很高兴,解决了回字型数字输出问题。祥见下文

mzyf5400 2008-08-30 11:09:19
// 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++;
}
}
}


...全文
151 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
mzyf5400 2008-08-31
  • 打赏
  • 举报
回复
想看有代码缩进的,请看我的博客:
http://blog.csdn.net/goldentimes1/archive/2008/08/30/2854004.aspx
mzyf5400 2008-08-30
  • 打赏
  • 举报
回复
// 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++;
}
}
}


第一次写源代码上来,不知道缩进的搞法,出了错,不好意思。
wuyu637 2008-08-30
  • 打赏
  • 举报
回复
up

64,648

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧