can anybody help me to solve this number pyramid using C program. The output will be 1st line 1, 2nd line 2 3, 3rd line 3 4 5, 4th line 4 5 6 7 etc.
Number Pyramid in C programming?
void main()
{
int x=1,max,i,j;
scanf("%d",%26amp;max);
for(i=1;i%26lt;=max;i++)
{
x=i;
for(j=1;j%26lt;=i;j++)
{
printf("\t%d",x++);
}
printf("\n");
}
}
try this and it will work until the level of the value specified by max...
output will be:
if max=10
1
2 3
3 4 5
4 5 6 7
5 6 7 8 9
6 7 8 9 10 11
7 8 9 10 11 12 13
8 9 10 11 12 13 14 15
9 10 11 12 13 14 15 16 17
10 11 12 13 14 15 16 17 18 19
Reply:int max
max = 10; // 10 can chg to other number
for (i = 1 ,i%26lt;=max,i++)
{
for (j = i , j%26lt;(2*i), j++)
{
printf (\t%d,j); //command to print j
}
printf ("\n"); // change line
}
Reply:use this method. (i write it according to VB)
DIM a,b,c=1;
for a=1 to 5
for b=1 to a
print c
c=c+1
next
next
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment