Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-16-2003, 08:23 AM   PM User | #1
Xiang
New Coder

 
Join Date: Jul 2002
Location: Malaysia
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
Xiang is an unknown quantity at this point
for

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
Xiang is offline   Reply With Quote
Old 02-17-2003, 09:34 AM   PM User | #2
DaZ
New Coder

 
Join Date: Dec 2002
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
DaZ is an unknown quantity at this point
Quote:
Originally posted by Xiang

for (a = 1; a <= 8; a++)
{ for (b = 8; b >= a; b--)
printf("%i\t", b);
printf("\n");
}
try this for your second for statement
-----------------------------------------------

ive just reversed the numbers that it prints out.


for (a = 8; a >= 1; a--)
{ for (b = 1; b <= a; b++)
printf("%i\t", b);
printf("\n");
}

see if thats ok
DaZ is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:55 AM.


Advertisement
Log in to turn off these ads.