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.

cheers
sh4rif

Attachments
2
Contributors
2
Replies
4
Views
7 Years
Discussion Span
Last Post by myk45

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

@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.