English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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.

2006-11-06 22:43:00 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

void main()
{
int x=1,max,i,j;
scanf("%d",&max);
for(i=1;i<=max;i++)
{
x=i;
for(j=1;j<=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

2006-11-06 23:12:30 · answer #1 · answered by compu-illiterate~Yeah tats me 2 · 0 0

int max

max = 10; // 10 can chg to other number

for (i = 1 ,i<=max,i++)
{
for (j = i , j<(2*i), j++)
{
printf (\t%d,j); //command to print j
}
printf ("\n"); // change line
}

2006-11-07 06:55:08 · answer #2 · answered by safrodin 3 · 0 0

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

2006-11-09 16:59:25 · answer #3 · answered by Shahid 1 · 0 0

fedest.com, questions and answers