Oct 12, 2011 at 6:48am UTC
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 Oct 12, 2011 at 8:00am UTC
Oct 12, 2011 at 7:05am UTC
One loop control the row,the other loop control the colum number.
Oct 12, 2011 at 7:15am UTC
did u tried so far???
where you are facing problem to implement??????
Oct 12, 2011 at 7:59am UTC
see below
Last edited on Oct 12, 2011 at 8:07am UTC
Oct 12, 2011 at 8:06am UTC
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");
}
Oct 12, 2011 at 3:06pm UTC
#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