主题:求教空格问题
遇到许多题目都是因为空格问题而输出错误,就想这两个:
打印菱形#include <stdio.h>
int main()
{
int n, i, j;
scanf("%d", &n);
for ( i = 1; i <= n; i++ )
{
for ( j = 0; j < n - i; j++ )
printf(" ");
for ( j = 1; j <= 2 * i - 1; j++ )
printf("*");
printf("\n");
}
for ( i = n - 1; i >= 0; i-- )
{
for ( j = 0; j < n - i; j++ )
printf(" ");
for ( j = 1; j <= 2 * i - 1; j++ )
printf("*");
printf("\n");
}
return 0;
}
还有打印数字三角形#include<stdio.h>
int main()
{
int n,i,j,t;
scanf("%d",&n);
t=2*(n-1);
for(i=1;i<=n;i++)
{
for(j=0;j<t;j++)
printf(" ");
t-=2;
for(j=1;j<=i;j++)
printf("%d",j);
for(j=i-1;j>=1;j--)
printf("%d ",j);
printf("\n");
}
return 0;
}
都是空格问题,哪位高手帮帮我这个菜鸟!!!
打印菱形#include <stdio.h>
int main()
{
int n, i, j;
scanf("%d", &n);
for ( i = 1; i <= n; i++ )
{
for ( j = 0; j < n - i; j++ )
printf(" ");
for ( j = 1; j <= 2 * i - 1; j++ )
printf("*");
printf("\n");
}
for ( i = n - 1; i >= 0; i-- )
{
for ( j = 0; j < n - i; j++ )
printf(" ");
for ( j = 1; j <= 2 * i - 1; j++ )
printf("*");
printf("\n");
}
return 0;
}
还有打印数字三角形#include<stdio.h>
int main()
{
int n,i,j,t;
scanf("%d",&n);
t=2*(n-1);
for(i=1;i<=n;i++)
{
for(j=0;j<t;j++)
printf(" ");
t-=2;
for(j=1;j<=i;j++)
printf("%d",j);
for(j=i-1;j>=1;j--)
printf("%d ",j);
printf("\n");
}
return 0;
}
都是空格问题,哪位高手帮帮我这个菜鸟!!!