below is one simplest code to illustare the pyramid of number.

``````void piramid(int const c)
{
int r, x;

for (r = c; r > 0; r--)
{
for (x = 1; x < = (2 * c - r); x++)
{
if (x < r) printf(" ");
else if (x <= c) printf("%d", x - r + 1);
else printf("%d", (2 * c - r) - x + 1);
}
printf("\n");
}
}``````

is there any other method that uses just the loop counters to print the pyramid with out the help of any other variables.

i just want to replace the statements `x - r + 1` and `(2 * c - r) - x + 1` by just r or x.

Thanks ,

Adter 80+ posts, don't you think it's time to learn how to FORMAT code?
2
Contributors
1
3
Views
8 Years
Discussion Span
Last Post by yila

i never seen one only with 2 vars.
but i wrote one yesterday with recursion, maybe not exactly what you're looking for, but it's a bit diff from yours

``````void pyramid (int x, int size)
{

int i=0;
int temp =0;

if(!x)
return;

pyramid(x-1,size);

temp = size - x;
while(temp)
{
printf(" ");
temp--;
}

for (i=1;i<=x;i++)
{

printf("%d",i);
}

for(i=x-1; i>=1; i--)
printf("%d",i);
printf("\n");

}``````
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.