[C] Implementation Method for printing the diamond pattern and printing the diamond pattern
Method 1: Split the diamond into two parts and print the content above and below in sequence.
Source code:
#include<stdio.h>
Int main()
{
/ / First write the upper part of the diamond
Int line = 0;
Printf ("Please enter the number of lines");
Scanf("%d",&line);
/ / According to the pattern, to output the upper part of the diamond, you need to use the for loop, loop output line output each line
//on
Int i = 0;
For(i=0;i<line;i++){
/ / Each line first outputs a space, and then output *
Int j = 0;
/ / Output space
For(j=0;j<line+1-i;j++){
Printf(" ");
}
//output*
For(j=0;j<2*i-1;j++){
Printf("*");
}
Printf("\n");
}
//under
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;
}