1. Output a diamond made of *
*
**
***
****
***
**
*
The idea of this problem is to think of this diamond as up and down two parts, belong to the use of circular statements written, looking for space and * between the law, such as the first line preceded by a space has a *, the second line to reduce a space plus a * so loop.
#include <stdio.h>
int main ()
{
int line = 0; Defines an integer variable line number. Suppose line is 7
int i = 0; Defining Shaping Variables I
scanf_s ("%d", &line); Number of input lines
for (i = 0; i < line; i++)//"Upper half of print" for loop,i< number of lines; i++
{
int j = 0; Define a shaping variable J
for (j = 0, J < line-i-1; j + +)//inline for loop "Print each line" when i=0 outputs first line, J Loop
{
printf (""); "Print Space" when i=0, j<6, output 6 spaces
}
for (j = 0; J < 2 * i + 1; j + +)//inline for loop
{
printf ("*"); "Print *" I equals 0, output A *, loop
}
printf ("\ n");
}//"Print bottom half"
for (i = 0; i < line-1; i++)
{
int j = 0;
for (j = 0; J < i + 1; j + +)
{
printf ("");
}
for (j = 0; J < 2 * (Line-1-i)-1; j + +)
{
printf ("*");
}
printf ("\ n");
}
return 0;
}