0

I have to get the desired output as follows:

1 
2 6
3 7 10
4 8 11 13
5 9 12 14 15

But I can't seem to figure out how to do it. All I get is:

1 
2 6
3 7 6
4 8 7 6
5 9 8 7 6

Here is my code:

#include<stdio.h>
int main()
    {
      int n,i,j;
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
        for(j=0;j<i;j++)
        {
          if((j+1)==1)
            printf("%d ",i);
          else
            printf("%d ",i+n-j);
        }
        printf("\n");
      }
      return 0;
    }

But I understood the desired output: I have to print the numbers from 1 to 15 in ascending order like a right angled triangle.

1 Answers1

0
#include <stdio.h>

#define SZ 5

int main()
{
    int i,j, add = SZ, val[SZ+1] = {1};
    for( j=1; j<=SZ; ++j )
    {
        for( i=0; i<j; ++i )
            printf( "%2d ", val[i]++ );
        printf( "\n" );
        val[j] = val[j-1] + --add;
    }
}
sp2danny
  • 7,488
  • 3
  • 31
  • 53