0

Hello every one!

i want to create something like this (show at the bottom of this message as an attachment) but i've no clue how to create this digital payrmid.

can anyone please help me with the code please?

thanks for your help in advance

cheers
sh4rif

Attachments pyramid.gif 5.76 KB
2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by myk45
0

Ok, you can use a recursive method for this.

1) Write a function to print each row, i.e say row number 3 is:
1 2 3 2 1

The function to do this can be done like this:

Let max be a global variable, indicating the maximum number of each row.

void print(int n)
{
        if (n == max) {
                printf("%d", n);
                return;
        } else {
                printf("%d", n);
                print(n + 1);
                printf("%d", n);
        }
}

2) Now, the task is pretty simple. Do the following:

for (i = 1; i <= no_of_rows; i++) {
        max = i;
        /* print appropriate number of spaces */
        print(i);
}

for (i = no_of_rows - 1; i > 0; i--) {
        max = i;
        /* print appropriate number of spaces */
        print(i);
}

Edited by myk45: n/a

0

@Moderators

Oops, i posted twice by mistake. Please delete this post.

Edited by myk45: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.