Thursday, January 1, 2015

pattern-4

1:
#include<stdio.h>
int main()
{
    int row,space,star,n;
    printf("please enter the number of lines:");
    scanf("%d",&n);
    for(row=1;row<=n;row++)
    {
        for(space=n-row;space>=0;space--)
    {
            printf(" ");
    }
    for(star=1;star<=2*row-1;star++)
    {
        printf("*");
    }
    printf("\n");
    }
    for(row=n;row>=1;row--)
    {
        for(space=n-row;space>=0;space--)
    {
            printf(" ");
    }
    for(star=1;star<=2*row-1;star++)
    {
        printf("*");
    }
    printf("\n");
    }
return 0;
}

input: 7
output:             
                                                        *
                                                      ***
                                                    *****
                                                  *******
                                                *********
                                              ***********
                                            *************
                                            *************
                                              ***********
                                                *********
                                                  *******
                                                    *****
                                                      ***
                                                        *
                                         

No comments:

Post a Comment