打印关于一系列的####的图型

MZJCDD 2008-04-16 10:11:01
#
# # #
# # # # #
# # # # # #
# # # # # # #
怎么写个程序打印出来这样的图形????
...全文
72 10 打赏 收藏 举报
写回复
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
星羽 2008-04-17
  • 打赏
  • 举报
回复

#
###
#####
#######
#########
###########
星羽 2008-04-17
  • 打赏
  • 举报
回复

#include "iostream"
#include "iomanip"
using namespace std;

int main() {

for (int i = 0; i <= 5; ++i)
cout<<setfill(' ')<<setw(5 - i)<<""<<setfill('#')<<setw(i * 2 + 1)<<""<<endl;
return 0;
}

kbh1984 2008-04-17
  • 打赏
  • 举报
回复
如果是
 #
# # #
# # # # #
# # # # # # # 的话
#include <iostream.h> 
#include <iomanip.h>
void main()
{
int i;
for( i=0;i <4;i++)
{
cout <<setw(5-i) <<'#';
for(int j=0;j<2*i;j++)
{
cout <<setw(2) <<'#';
}
cout<<endl;
}
}
冰矿 2008-04-17
  • 打赏
  • 举报
回复
利用函数

#include <iostream>
using namespace std;
void line(char symbol, char n)
{
int i;
for (i = 0; i < n; i++) cout<<symbol<<' ';
}
int main()
{
int i,n;
cout<<"输入一个整数:"; cin>>n;
for (i = 0; i < n; i++)
{
line(' ',n-i); line('#',i*2+1); cout<<endl;
}

system("PAUSE");
return 0;
}
luo_yu_ 2008-04-17
  • 打赏
  • 举报
回复
等腰三角形:
#include<stdio.h>
void main()
{
int a,b,c;
for(a=1;a<=9;a++)
{
for(b=1;b<=9-a;b++)
{
printf(" ");
}
for(c=1;c<=2*a-1;c++)
{
printf("#");
}
printf("\n");
}
}
菱形:
#include<stdio.h>
void main()
{
int a,b,c;
for(a=1;a<=9;a++)
{
for(b=1;b<=9-a;b++)
{
printf(" ");
}
for(c=1;c<=2*a-1;c++)
{
printf("#");
}
printf("\n");
}
for(a=1;a<=8;a++)
{
for(b=1;b<=a;b++)
{
printf(" ");
}
for(c=1;c<=2*(8-a)+1;c++)
printf("#");
printf("\n");
}
}
平行四边形:
#include<stdio.h>
void main()
{ int a,b,c;
for(a=0;a<=6;a++)
{
for(b=0;b<=6-a;b++)
{
printf(" ");
}
for(c=0;c<=10;c++)
{
printf("#");
}
printf("\n");
}
}
f22fbi 2008-04-16
  • 打赏
  • 举报
回复
你的图形有问题吧
应该是
#
# # #
# # # # #
# # # # # # #
应该是以2递增吧
如果是这样,输出n行的代码如下

#include<iostream>
using namespace std;

int main()
{
int n;
cout<<"Input n:";
cin>>n;
for (int i=0;i!=n;++i){
for (int j=n-i-1;j!=0;--j)
cout<<' ';
for (int j=0;j!=2*i+1;++j)
cout<<'#';
cout<<endl;
}
return 0;
}

softking1 2008-04-16
  • 打赏
  • 举报
回复
利用FOR循环
younel0921 2008-04-16
  • 打赏
  • 举报
回复
算法:左侧每行从某一个位置开始,输出空格每行空格数是上一行的个数减一然后输出#
iwknow 2008-04-16
  • 打赏
  • 举报
回复
#include <iostream>
using namespace std;
void main()
{
cout<<" #"<<endl;
cout<<" ###"<<endl;
cout<<" #####"<<endl;
cout<<" #######"<<endl;
cout<<" #########"<<endl;
}
另一种方法:
#include <iostream>
using namespace std;
void main()
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=5-i;j>0;j--)
cout<<" ";
for(k=i*2-1;k>0;k--)
cout<<"#";
cout<<endl;
}
}
Inhibitory 2008-04-16
  • 打赏
  • 举报
回复
#include <iostream>
using std::cout;
using std::endl;
int main() {
cout <<" #" << endl;
cout << " # # #" << endl;
cout << " # # # # #" << endl;
cout << " # # # # # #" << endl;
cout << " # # # # # # #"<<endl;

return 0;
}
相关推荐
发帖
C++ 语言

6.3w+

社区成员

C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
帖子事件
创建了帖子
2008-04-16 10:11
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下