c++中用循环语句打印如下图的图案

来源:百度知道 编辑:UC知道 时间:2024/06/04 20:02:19
#
# # #
# # # # #
# # # # # # #

1.如果前头没有空格的话
#include<conio.h>
#include<stdio.h>

void main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=(1+(i-1)*2);j++)
printf("#");

printf("\n");
}
getch();
}

2.如果前头有空格的话
#include<conio.h>
#include<stdio.h>

void main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=(4-i);j>=0;j--)
printf(" ");
for(j=1;j<=(1+(i-1)*2);j++)
printf("#");

printf("\n");
}
getch();
}

#include <iostream>
using namesapce std;
void print_sharp(int n=4){
int row_num=n;
for(int i=0;i<row_num;i++){
for(int j=0;j<2*row_num-1;j++){
cout<<"#";
}
cout<<endl;
}
}
void main(){<