用c++编写程序输出以下图案(数字也要哦: 1 * 2 *** 3 ***** 4******* 5 ***** 6 *** 7 *

1 *
2 ***
3 *****
4*******
5 *****
6 ***
7 *
结果应该是这样才行,而且,输出要包括数字啊,最好能用循环结构!谢谢大伙啦。。。。

第1个回答  2013-03-15
本来都不想回答的,还是写个玩玩吧。
你可以把X的值改成其他的奇数,我的方法是通用的,你仔细体会一下吧。
但是输出的行号占的位数多的时候,会发生变形,你可以修正 一下。

#include <iostream>
using namespace std;
int main()
{
int x = 7;
for (int i= 1;i<= x;i++)
{
cout<<i;
for (int j= 1;j<=x;j++)
{
if ( abs((x+1)/2 - j ) >= (x + 1)/ 2 - abs( i - (x + 1)/2 ) )
{
cout<<' ';
}
else
cout<<'*';
}
cout<<endl;
}
//system("pause");
return 0;
}本回答被提问者和网友采纳
第2个回答  2013-03-15
#include "stdio.h"
void main()

{
int Row;
int Line;
int Temp;
int Nomber = 7;
for (Row = 0; Row < (Nomber + 1)/2; Row++)
{
printf_s("%d", Row + 1); //新添加的。
for (Line = 0; Line < ((Nomber + 1)/2 - 1) - Row; Line++)
{
printf_s(" ");
}
for (Temp = 0; Temp <= 2*Row; Temp++)
{
printf_s("*");
}
printf_s("\n");
}
for (Row = 0; Row < ((Nomber + 1)/2 - 1); Row++)
{
printf_s("%d", Row + 5); // 新添加的。
for (Line = 0; Line <= Row; Line++)
{
printf_s(" ");
}
for (Temp = 0; Temp <= ((Nomber + 1)/2 - 2*Row); Temp++)
{
printf_s("*");
}
printf_s("\n"); //你要是vc6.0 就修改为printf
}
}

我替你做了。。无语了。估计你在纠结。。我说话有点火,希望你用心学习。。。

基本思想都给你了,你敢不敢自己动点脑子??你这种态度态度真心没法学好C++。。这么简单的问题,你都解决不了?
你控制一下,每行的第一个输出数字,从第二个开始循环不会??稍微动个脑子啊,大神。。。追问

谢谢!!!!

相似回答