这个题怎么做?

hezhao88 2009-05-13 08:03:34



怎样用“*”输出一个菱形?

...全文
92 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
hezhao88 2009-05-13
  • 打赏
  • 举报
回复
谢谢各位!
我想要的是循环输出的!
呵呵
cyldf 2009-05-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wolflion 的回复:]
C/C++ code
# include <iostream>
using namespace std;

int main(void)
{
cout << " * " << endl;
cout << " *** " << endl;
cout << " ***** " << endl;
cout << " *** " << endl;
cout << " * " << endl;
cin.get();
}




这是你要的吗?呵呵
[/Quote]
很好很强大,哈哈
na2650945 2009-05-13
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wolflion 的回复:]
C/C++ code
# include <iostream>
using namespace std;

int main(void)
{
cout << " * " << endl;
cout << " *** " << endl;
cout << " ***** " << endl;
cout << " *** " << endl;
cout << " * " << endl;
cin.get();
}




这是你要的吗?呵呵
[/Quote]
还是这个直接。
zhangxun2007 2009-05-13
  • 打赏
  • 举报
回复
可以分成上下两个三角形依次输出
使用for循环以及setw进行控制

#include "stdio.h"

void main()
{
int i,j,h;
printf("输入高度:\n");
scanf("%d",&h);
for(int i=1;i<=h;i++)
{
setw(i+h/2);
j=1
for(;j<=i;j++)
printf("*");
printf("\n");
}
for(int i=h-1;i>=1;i--)
{
setw(i+h/2);
j=1
for(;j<=i;j++)
printf("*");
printf("\n");
}


  • 打赏
  • 举报
回复

把菱形分为两部分来输出,上面的三角形和下面的三角形
wolflion 2009-05-13
  • 打赏
  • 举报
回复

# include <iostream>
using namespace std;

int main(void)
{
cout << " * " << endl;
cout << " *** " << endl;
cout << " ***** " << endl;
cout << " *** " << endl;
cout << " * " << endl;
cin.get();
}


这是你要的吗?呵呵
magipan 2009-05-13
  • 打赏
  • 举报
回复
这种问题还是STFW吧
机智的呆呆 2009-05-13
  • 打赏
  • 举报
回复
up~
lingyin55 2009-05-13
  • 打赏
  • 举报
回复

#include "stdio.h"

void main()
{
int h;
printf("输入高度-》 ");
scanf("%d",&h);
for(int i=1;i<=h;i++)
{
for(int a=1;a<=(h-i);a++)
{
printf(" ");
}
for(int b=1;b<=(i*2-1);b++)
{
printf("*");
}
printf("\n");
}
for(int j=h-1;j>=1;j--)
{
for(int a=1;a<=(h-j);a++)
{
printf(" ");
}
for(int b=1;b<=(j*2-1);b++)
{
printf("*");
}
printf("\n");
}
}

Paradin 2009-05-13
  • 打赏
  • 举报
回复
printf(" *\n**\n *");

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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