Imnoob - 1 month ago 5x
C Question

# Reverse pyramid using same row number

I encountered the following question which ask you to print the reverse pyramid. Using same number as row number,all of my results are like reverse pyramid following (2i-1) number of terms in each row.
The other one is:

``````#include <stdio.h>

int main()
{
int i, j, row;
printf ("Enter the no of rows");
scanf ("%d", &row);
for (i = row; i >= 1; i--)
{
for (j = 1; j <= i; j++)
{
printf ("%d", i);
}

printf ("\n");
}
return 0;
}
``````

what changes should I make in the above program to get the desired result.
some homework which I did: searched several sites which explains C and has examples related to it. Closest which I could get was this
http://www.techcrashcourse.com/2016/01/print-reverse-pyramid-star-pattern-in-c.html

Then added a new loop:

for(k=3;k<=row-i;k++);

printf(" ");

and changed the initial value of "K" several times but it did not work out.

Answer

it's not particularly easy to guess what you had in mind, but regarding linked question, it should be done as follows:

``````#include <stdio.h>
int main()
{
int i , j, k, row;
printf ("Enter the no of rows");
scanf ("%d",&row);
for (i=row;i>=1;i--)
{
for(k = 0;k<row - (i-1);k++)
{
printf (" ");
}
for (j=1;j<=i;j++)
{
printf ("%d",i);
printf(" ");
}
printf ("\n");
}
return 0;
}
``````

also, next time please post your results.

Source (Stackoverflow)
Comments