Xiang
02-16-2003, 08:23 AM
Dear sir,
I use for loop to produce the following output, but my second for can't be functioned properly .
Proper output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
#include <stdio.h>
#include <conio.h>
void main(void)
{
int a;
int b;
clrscr();
for (a = 1; a <= 9; a++)
{ for (b = 1; b <= a; b++)
printf("%i\t", b);
printf("\n");
}
for (a = 1; a <= 8; a++)
{ for (b = 8; b >= a; b--)
printf("%i\t", b);
printf("\n");
}
getch();
}
Thanks
Xiang
I use for loop to produce the following output, but my second for can't be functioned properly .
Proper output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
#include <stdio.h>
#include <conio.h>
void main(void)
{
int a;
int b;
clrscr();
for (a = 1; a <= 9; a++)
{ for (b = 1; b <= a; b++)
printf("%i\t", b);
printf("\n");
}
for (a = 1; a <= 8; a++)
{ for (b = 8; b >= a; b--)
printf("%i\t", b);
printf("\n");
}
getch();
}
Thanks
Xiang