Before I saw some articles on the internet about how to print the diamond, but not the same as I asked at that time, the online code output when each adjacent diamond has no space.
What I'm going to introduce is a code with spaces between each of the adjacent diamonds.
The exercises and code are as follows:
A solid diamond with a * output edge length of N.
*
* *
* * *
* *
*
printf ("Please enter an integer:");
int n = 0;
scanf ("%d", &n);
Print the number of lines, note that it must be an odd line, so it is 2n-1
for (int i = 1; I <= 2*n-1; i++)
{
ABS () is the absolute value function, the number of spaces per line =|n-lines |. Note that the number of spaces here refers to the number of spaces before the * number!!
for (int j = 1; J <= Abs (N-i); j + +)
{
printf ("");
}
Each line of "*" =n-|n-i|. Note Because the remaining rows require more than one * to be printed, except for the first and last lines, you only need to add a space after the *.
for (int k = 1; k <= N-abs (n-i); k++)
{
printf ("*");
}
printf ("\ n");
}
Use the C language to print the diamond with A For loop (with spaces for each adjacent diamond)