i need to write the code for this problem:
Q:write a c program to print a pyramid of digits as shown below for n number of lines.
1
2 3 2
3 4 5 4 3
4 5 6 7 6 5 4
-- -- -- -- -- -- -- --
Actually i have the code as well.But something is wrong. heres the code:
Code:
/*program to print digits in pyramidal form*/
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k,l,m,n;
clrscr();
printf("\n how many lines?");
scanf("%d",&n);
/*loop 1 to print n lines*/
for(l=1;l<=n;l++)
{
/*loop 2 to print spaces*/
for(i=1;i<=n-l;i++)
printf("       ");
/*loop to print digits in the left side of axis*/
m=l;
for(j=1;j<=l;j++)
{
printf("%6d",m);
m++;
}
/*loop to print digits rightside of axis*/
m=m-2;
for(k=1;k<l;k++)
{
printf("%6d",m);
m--;
}
printf('\n");
}
getch();
}
i ran the code on borlands turbo c++ 3.0 and in the output only the right
side of the axis came. i am unable to figure out the mistake in the code.
thanx in advance.