1:数字金字塔
int main()
{
int m,i,n,j;
for(m=1;m<=9;m++)
{
i,n=1;
for(i=1;i<=9-m;i++)
{
printf(" ");
}
for(n=1;n<=m;n++)
{
printf("%d",n);
}
for(j=m-1;j>0;j--)
{
printf("%d",j);
}
printf("n");
}
}
2:
int main()
{
int i, space, rows, k=0, count = 0, count1 = 0;
printf("行数: ");
scanf("%d",&rows);
for(i=1; i<=rows; ++i)
{
for(space=1; space <= rows-i; ++space)
{
printf(" ");
++count;
}
while(k != 2*i-1)
{
if (count <= rows-1)
{
printf("%d ", i+k);
++count;
}
else
{
++count1;
printf("%d ", (i+k-2*count1));
}
++k;
}
count1 = count = k = 0;
printf("n");
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)