Print a solid diamond
mission details
Input n and output the following pattern:
the input n in the above example is 4.
Requirements: use for loop to achieve
AC code
#include <stdio.h>
int main()
{
int i, j, k, n;
scanf("%d", &n);
//输出上半菱形
for(i = 1;i <= n;i++)
{
for(k = 1;k <= n-i;k++)
printf(" ");
for(j = 1;j < 2*i;j++)
printf("*");
printf("\n");
}
//输出下半菱形
for(i = n-1;i >= 1;i--)
{
//i=3,2,1
for(k = 1;k <= n-i;k++)
printf(" ");
for(j = 1;j < 2*i;j++)
printf("*");
printf("\n");
}
return 0;
}