0

I've reached the point where I can create a pyramid but have an extra dot in the last row. Can't seem to remove it . Is there something i'm doing wrong in the nested 'for' function?

Mario Output_2

#include <stdio.h>
#include <cs50.h>

int get_positive_int(void);

//Print Pyramid #s
int main(void)
{
    int n = get_positive_int();
    for (int i=0 ; i < n ; i++)
    {
        for (int j=i; j < n; j++)
        {
            printf(".");
        }
            for (int j=n-i; j <= n; j++)
            {
                printf("#");
            }
        printf("\n");
    }
}

// Prompt  for Height as +ve integer between 1 and 8
int get_positive_int(void)
{
    int n;
    do
    {
        n = get_int("Height: ");
    }
    while (n < 1 || n > 8 );
    return n;
}

1
  • Perhaps think about it another way: there is an extra dot in every row. – DinoCoderSaurus Aug 23 '20 at 13:18
0

@Dinocodersaurus is right. You're sooo close. Maybe you could modify the for loop that's printing dots(spaces) to print just one less on each row????

Dino, when are you going to stop giving answers as comments???? ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .