Problem C 4-9 printed in a diamond pattern (15 minutes)

Well after a long time only to write, but also changed the change em
this question requires programming, print a height of n by the "*" diamond pattern being composed.

Input format:
input gives a positive odd number n in a row.

Output format:
Output from the n asterisks "*" composed of diamond, as shown in the sample. Each asterisk followed by a space.

Sample input:
7

Sample output:

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

#include <stdio.h>
int main()
{
    int n,m,a=0,i=1;
    scanf("%d",&n);
        for(i;i<=n;i=i+2){
            for(m=i;m<n;m++){
                printf(" ");
            }
            for(a;a<i;a++){
                printf("* ");
            }
            a=0;
            printf("\n");
        }
        for(i=i-4;i>0;i=i-2){
            for(m=i;m<n;m++){
                printf(" ");
            }
            for(a;a<i;a++){
                printf("* ");
            }
            a=0;
            printf("\n");
        }
    return 0;
}
Published 24 original articles · won praise 0 · Views 312

Guess you like

Origin blog.csdn.net/Priest_One/article/details/104083422