Use the C language and use for loop to print the diamond (each adjacent diamond must contain spaces ).
I have seen some articles on the Internet that show how to print the diamond, but they are different from what I asked at the time. When the online code is output, each adjacent diamond does not contain spaces.
I am introducing the Code with spaces between each adjacent diamond.
The exercises and Code are as follows:
Use a solid diamond with * output side length of n.
*
**
***
**
*
Printf ("enter an integer :");
Int n = 0;
Scanf ("% d", & n );
// Print the number of rows. Note that the number of rows must be an odd number, so the number is 2n-1.
For (int I = 1; I <= 2 * n-1; I ++)
{
// Abs () is an absolute value function. The number of spaces in each line is = | n-number of rows |. Note that the number of spaces here refers to the number of spaces before !!
For (int j = 1; j <= abs (n-I); j ++)
{
Printf ("");
}
// "*" = N-| n-I | of each row. Note that, except for the first and last rows, multiple * Rows need to be printed, so you only need to add spaces after.
For (int k = 1; k <= n-abs (n-I); k ++)
{
Printf ("*");
}
Printf ("\ n ");
}