4 回答
TA贡献1801条经验 获得超16个赞
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
TA贡献1785条经验 获得超8个赞
你自己要改一下,输出位置为一个空格的全部改成两个,其他的不用改):
实心的:
#include<stdio.h>
int n;
void draw(int n)
{
int i,j;
for (i=1-(n>>1);i<=n;i++)
if (i>=0)
{
for (j=0;j<i;j++) printf(" ");
for (j=1;j<=2*(n-i)+1;j++) printf(" *");
printf("\n");
}
else
{
for (j=i;j<0;j++) printf(" ");
for (j=1;j<=n+2*i+1;j++) printf(" *");
for (j=1;j<=-1-2*i;j++) printf(" ");
for (j=1;j<=n+2*i+1;j++) printf(" *");
printf("\n");
}
}
int main()
{
printf("Please input the size (n>=4):");
scanf("%d",&n);
draw(n);
return 0;
}
空心的:
#include<stdio.h>
int n;
void draw(int n)
{
int i,j;
for (i=1-(n>>1);i<=n;i++)
if (i>0)
{
for (j=0;j<i;j++) printf(" ");
for (j=1;j<=2*(n-i)+1;j++)
if (j==1||j==2*(n-i)+1) printf(" *");
else printf(" ");
printf("\n");
}
else
if (i==0)
{
printf(" *");
for (j=1;j<n;j++) printf(" ");
printf(" *");
for (j=1;j<n;j++) printf(" ");
printf(" *\n");
}
else
{
for (j=i;j<0;j++) printf(" ");
for (j=1;j<=n+2*i+1;j++)
if (i==1-(n>>1)) printf(" *");
else if (j==1||j==n+2*i+1) printf(" *");
else printf(" ");
for (j=1;j<=-1-2*i;j++) printf(" ");
for (j=1;j<=n+2*i+1;j++)
if (i==1-(n>>1)) printf(" *");
else if (j==1||j==n+2*i+1) printf(" *");
else printf(" ");
printf("\n");
}
}
int main()
{
printf("Please input the size (n>=4):");
scanf("%d",&n);
draw(n);
return 0;
}
TA贡献1810条经验 获得超5个赞
/*
用C语言输出:
* *
* * *
* *
*
*/
#include <stdio.h>
int main()
{
int a[4][7] ={{0,1,0,0,0,1,0},{1,0,0,1,0,0,1},{0,1,0,0,0,1,0},{0,0,0,1,0,0,0}};
for(int i=0;i<4;i++) /*输出行*/
{
for(int j=0;j<7;j++) /*输出列*/
{
if(a[i][j] !=0)
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0;
}
//这是我用索引数组的方法写的。
添加回答
举报