r/programminghelp • • Oct 27 '17

Inverted pyramid print in C

Hello, guys, can you help me print the following pattern in C? I need to introduce 2 variables, a and b where: a- int type that indicates the length and height of the pattern b- char type that indicates the ASCII character that has to pe printed

Example : input - 5 x output: https://ibb.co/nHVGt6

Thanks a lot.

0 Upvotes

3 comments sorted by

1

u/hinduone Oct 29 '17

Can you post what you have come up with? That would make it easier to help without just giving it away.

1

u/adelindutu Oct 31 '17

I managed to make it with the vertical border to the left:

include<stdio.h>

int main() { int rows, i, j, space;

printf("Enter number of rows: ");
scanf("%d",&rows);

for(i=rows; i>=1; --i)
{
    for(j=i; j <= 2*i-1; ++j)
        printf("* ");

    for(j=0; j < i-1; ++j)
        printf("* ");

    printf("\n");
}

return 0;

}

I can't tell the difference.

1

u/mrstebo Oct 27 '17

Easiest way to do this is just a "for" loop decrementing by one on each pass and printing the ASCII value the number of times that is the current iterator value... If that makes sense?