够吗

daolaAmeng 2008-03-28 09:48:54
*
***
*****
*******
*****
***
*
请问只用c语言中的while语句和for语句能编出一个程序显示上面的图形,用到嵌套了把,谢谢帮忙!!给我提示,我自己编程序。
...全文
108 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
C334745710 2008-03-31
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 HelloDan 的回复:]
C/C++ code
#include <stdio.h>



int main()
{
int i,j;
char test[7][7]={
{' ',' ',' ','*',' ',' ',' '},
{' ',' ','*','*','*',' ',' '},
{' ','*','*','*','*','*',' '},
{'*','*','*','*','*','*','*'},
{' ','*','*','*','*','*',' '},
{' ',' ','*','*','*',' ',' '},
{' ',' ',' ','*',' ',' ',' '},
};
for(i=0;i<7;++i)
{
for(j=0;j<7;…
[/Quote]
顶!!!!嘿嘿.///
ttlyfast 2008-03-31
  • 打赏
  • 举报
回复
HelloDan 2008-03-31
  • 打赏
  • 举报
回复

#include <stdio.h>


#define N 7

int main()
{
int i,j,k;

for(i=0;i<N/2+1;++i)
{
for(k=0;k<(N-2*i)/2;++k)
printf(" ");
for(j=0;j<=2*i;++j)
printf("*");
printf("\n");
}

for(i=0;i<N/2;++i)
{
for(j=0;j<i+1;++j)
printf(" ");
for(k=(N-(i+1)*2);k>0;--k)
printf("*");
printf("\n");
}


return 0;
}

HelloDan 2008-03-30
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 abupie 的回复:]
楼上这个太偷懒了。。。。
[/Quote]

只是讨论各种方法罢了,不过这个应该是最简单的,不过也有点麻烦,通用性不强。
linhui1314 2008-03-30
  • 打赏
  • 举报
回复
6楼的却是最简洁的。
abupie 2008-03-30
  • 打赏
  • 举报
回复
楼上这个太偷懒了。。。。
HelloDan 2008-03-30
  • 打赏
  • 举报
回复

#include <stdio.h>



int main()
{
int i,j;
char test[7][7]={
{' ',' ',' ','*',' ',' ',' '},
{' ',' ','*','*','*',' ',' '},
{' ','*','*','*','*','*',' '},
{'*','*','*','*','*','*','*'},
{' ','*','*','*','*','*',' '},
{' ',' ','*','*','*',' ',' '},
{' ',' ',' ','*',' ',' ',' '},
};
for(i=0;i<7;++i)
{
for(j=0;j<7;++j)
printf("%c",test[i][j]);
printf("\n");
}


return 0;
}


daolaAmeng 2008-03-30
  • 打赏
  • 举报
回复
#include <stdio.h>
void main()
{
int i,j,k,t,count=1,m;
printf("请输入菱形半径");
scanf("%d",&m);
t=m-1,k=1;
do{
for(i=1;i<=t;i++)
printf("%c",32);
for(j=1;j<=k;j=j+1)
printf("%c",42);
printf("\n");
k=k+2,t=t-1,count++;
}while(count<=m);

do{
for(i=-1;i<=t;i++)
printf("%c",32);
for(j=5;j<=k;j=j+1)
printf("%c",42);
printf("\n");
k=k-2,t++,count++;
}while(count<=(2*m-1));


}
谢谢你们,我是初学者,有些东东我不是很懂,所以就用我学到的for和do while做了这个,谢谢大家支持!
51365133 2008-03-28
  • 打赏
  • 举报
回复
够了,再来人,分都不好分了.
51365133 2008-03-28
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 akirya 的回复:]
C/C++ code
#include <iostream>
#include <string>
using namespace std;


int main(int argc, char* argv[])
{
int n=5;
for(int x = 1 ;x < n*2 ; x++ ){
for(int y = 1 ; y < n*2 ; y++){
if( abs( x - n ) + abs( y - n ) >= n )
printf(" ");
else
printf("*");
}
printf("\n");
}
return 0;
}
[/Quote]
  • 打赏
  • 举报
回复

#include <iostream>
#include <string>
using namespace std;


int main(int argc, char* argv[])
{
int n=5;
for(int x = 1 ;x < n*2 ; x++ ){
for(int y = 1 ; y < n*2 ; y++){
if( abs( x - n ) + abs( y - n ) >= n )
printf(" ");
else
printf("*");
}
printf("\n");
}
return 0;
}
ryfdizuo 2008-03-28
  • 打赏
  • 举报
回复
定义一个char数组,初始化全部为空格,
前几行是将中间的位置上赋为'*'
后面几行是将尾部还原为空格;
当然了每次输出数组:puts()

69,382

社区成员

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

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