C practical exercise topic 23 – printing diamond pattern

Time:2020-9-30

Title:Print the following pattern (diamond).

   *
  ***
 *****
*******
 *****
  ***
   *

Program analysis:Firstly, the graph is divided into two parts: the first four lines have a rule, and the last three lines have a rule. Using the double for loop, the first level controls the row and the second level controls the column.

example:

#include 
 int main()
 {
     int i,j,k;
     for(i=0;i<=3;i++) {
         for(j=0;j<=2-i;j++) {
             printf(" ");
         }
         for(k=0;k<=2*i;k++) {
             printf("*");
         }
         printf("\n");
     }
     for(i=0;i<=2;i++) {
         for(j=0;j<=i;j++) {
             printf(" ");
         }
         for(k=0;k<=4-2*i;k++) {
             printf("*");
         }
         printf("\n");
     }
   
 }

The output results of the above examples are as follows:

   *
  ***
 *****
*******
 *****
  ***
   *

Thank you for your reading, please feel with your heart! Hope to help you who love learning!! Sharing is also a kind of happiness!!! Please relay…

Click to view the original text, thank you!