<#include stdio.h>
<#include stdlib.h>
<#include conio.h>
String s = "":
int num = 121;
int sum = 0; int height;
printf("Enter height: "); scanf("%d", &height);
printf("%d \n", 1);
for (int i = 2; i < height; i++)
{
s = "";
printf("%d \n", num);
while (num / 10 > 0)
{
sum = num % 10 + num / 10 % 10;
num = num/10;
s = s + itoa(sum);
}
num = atoi("1" + s + "1");
}
2006-08-10 21:02:38
·
answer #1
·
answered by Taki 2
·
0⤊
0⤋
First of all Input the order of the triangle i.e height.
Then dynamically allocate a 2-d matrix for that order.
Then fill that 2-d matrix with ones.
Start with the second row and follow it-
p[i][j] = p[i-1][j-1]+p[i-1][j];
now print the matrix in a triangular fashion and you are done
or do you need the codes ?
2006-08-11 19:15:44
·
answer #2
·
answered by ccsCoder 3
·
0⤊
0⤋
Here's a link to a contest with a similar attempt. Just modify their code so it outputs numbers and you're done.
http://www.wizardsolutionsusa.com/forum/showthread.php?t=797
2006-08-10 19:39:24
·
answer #3
·
answered by Charles G 4
·
0⤊
0⤋
1
121
1331
14641
....
You can do the following in a recursive manner.
2006-08-10 19:39:04
·
answer #4
·
answered by ali 6
·
0⤊
0⤋
#include
#include
void main()
{
int j,i,k;
clrscr();
for(i=1;i<3;i++)
{
printf("\n ");
for(j=1;j<=i;j++)
{
printf(" %d",j);
if(j=i)
{
for(k=j;k>=1;k--)
{
printf(" %d",k);
if(k==1)
break;
}
}
}
}
printf("\n%d %d",j,i);
getch();
}
2006-08-11 21:10:45
·
answer #5
·
answered by Jijo 2
·
0⤊
0⤋