一道循环的题目

tanwei0238 2008-03-27 05:09:09
7 6 5 4 3 2 1
1 2 3 4 5 6
6 5 4 3 2
2 3 4 5
5 4 3
3 4


就上面的数字,怎么编程,谢谢了
...全文
109 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hcon_1755 2008-03-27
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 ding1188 的回复:]
C/C++ code#include<iostream>
using namespace std;
void main()
{
int i,j,temp=7;
for(i=0;i<7;i++)//这里改成i<3就符合题目要求了~!~
{
for(j=temp;j>i;j--)
cout<<j<<" ";
cout<<endl;
for(++j;j<7-i;j++)
cout<<j<<" ";
cout<<endl;
temp=j-1;
}
}
[/Quote]

4楼你真的很象我一个很佩服的老师:陈哥~!~
spr614 2008-03-27
  • 打赏
  • 举报
回复
int i,j,tmp=7;
for(i = 0; i < 6; i++){
if(i%2 == 0){
for(j = tmp; j > i/2; j--){
cout << j << " ";
tmp = j;
}
}
else{
for(j = tmp; j < 7-i/2; j++){
cout << j << " ";
tmp = j;
}
}
cout << endl;
}
hcon_1755 2008-03-27
  • 打赏
  • 举报
回复
4楼的头像 很象我以前的面向对象老师....汗一个!!!! 真的很象~~
spr614 2008-03-27
  • 打赏
  • 举报
回复
int i,j,tmp=7;
for(i = 0; i < 6; i++){
if(i%2 == 0){
for(j = tmp; j > i/2; j--){
cout << j << " ";
tmp = j;
}
}
else{
for(j = tmp; j < 7-i/2; j++){
cout << j << " ";
tmp = j;
}
}
cout << endl;
}
qmm161 2008-03-27
  • 打赏
  • 举报
回复
分奇偶行来考虑
#include <iostream>

#define MAX 7

using namespace std;

int main()
{
int start,end;

for(int index=0;index<MAX-2+1;++index)
{
if(index%2==0)
{
for(int start=MAX-index/2;start>index/2;--start)
cout << start << " ";
}
else
{
for(int start=(index+1)/2;start<=MAX-(index+1)/2;++start)
cout << start << " ";
}
cout << endl;
}

system("PAUSE");
return 1;
}
qmm161 2008-03-27
  • 打赏
  • 举报
回复
4楼的方法很巧妙!
ding1188 2008-03-27
  • 打赏
  • 举报
回复
#include<iostream>
using namespace std;
void main()
{
int i,j,temp=7;
for(i=0;i<7;i++)
{
for(j=temp;j>i;j--)
cout<<j<<" ";
cout<<endl;
for(++j;j<7-i;j++)
cout<<j<<" ";
cout<<endl;
temp=j-1;
}
}

qmm161 2008-03-27
  • 打赏
  • 举报
回复
可以考虑用栈,每次干掉栈顶不显示,其余全部显示
taodm 2008-03-27
  • 打赏
  • 举报
回复
看奇偶行,自己找规律

64,647

社区成员

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

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