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

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);
}

@Moderators

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.