how to print a triangle in this format

closed account (2yC2Nwbp)
Hi All,

I am trying to print the triangle of numbers in the following format, Please suggest how to print :

format 1:

1
12
123
1234
12345
123456


format 2:

123456
12345
1234
123
12
1

Last edited on
One loop control the row,the other loop control the colum number.
did u tried so far???
where you are facing problem to implement??????
closed account (2yC2Nwbp)
see below
Last edited on
closed account (2yC2Nwbp)
actually the format I shown above is not coming as I want due to some alignment of the website here.
I am putting hyphen in places of spaces, (I want spaces or tabs only)

format 1:

----------1
--------12
------123
----1234
--12345
123456


format 2:

123456
--12345
---1234
-----123
------12
-------1

==========

here is the code that i used to print in the format shown initially

pattern1 code

for(i = 1; i <= m_nNumberCount; i++) {
for(j = 1; j <= i; j++) {
printf("%d ",j);
}
printf("\n");
}

pattern 3 code

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

for(i=1;i<=num;i++)
{
for(j=1;j<=i;j++)
printf("%d",j);
printf("\n");
}
return 0;
}

And try 2nd 4r ur assignment
Topic archived. No new replies allowed.