打印菱形问题代码(可输入大小)
(vc++6.0编译通过):#include<stdio.h>
int main(void)
{
int i, j, number;
printf("Input your number: ");
scanf("%i", &number);
for(i = 0; i < (2*number-1); ++i)
{
if( i < number -1)
{
for(j = 0; j < (2*number-1); ++j)
{
if( j == number-1 - i || j == number-1 + i )
printf("*");
else
printf(" ");
}
printf("\n");
}
else if( i == number -1)
{
for( j = 0; j < (2*number-1); ++j)
{
if( j == number-1-i || j == number-1 +i )
printf("*");
else
printf(" ");
}
printf("\n");
}
else
{
for( j = 0; j < (2*number-1); ++j)
{
if( ((i - number) == (j-1)) || ((i - number) == ( 2*number-3 - j)) )
printf("*");
else
printf(" ");
}
printf("\n");
}
}
return 0;
}