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 ,

WaltP commented: Adter 80+ posts, don't you think it's time to learn how to FORMAT code? -2

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