Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 25th, 2005, 12:27 PM   #1
kent666
Newbie
 
Join Date: Feb 2005
Location: mars
Posts: 2
Rep Power: 0 kent666 is on a distinguished road
Nested Loop Question

can anyone help me on how do i make this output:
*
**
***
****
*****

i know thats simple but i cant seem to figure it out using the nested loop.
my output just looks like this:
*
**
**
***
*****

Perhaps if anyone could help me. I could already figure out how to do this:
1
1 2
1 2 3
1 2 3 4
1 2 3
1 2
1
kent666 is offline   Reply With Quote
Old Feb 25th, 2005, 2:32 PM   #2
Xero
Hobbyist Programmer
 
Join Date: Dec 2004
Location: a cardboard box
Posts: 118
Rep Power: 4 Xero is on a distinguished road
Quote:
Originally Posted by kent666
can anyone help me on how do i make this output:
*
**
***
****
*****

i know thats simple but i cant seem to figure it out using the nested loop.
my output just looks like this:
*
**
**
***
*****

Perhaps if anyone could help me. I could already figure out how to do this:
1
1 2
1 2 3
1 2 3 4
1 2 3
1 2
1
I don't see how you could get an output like you did if you used a loop. This should be the correct implementation of the first one.
for (int i=1; i <= 5; i++){
  for (int j=i; j > 0; j--)
    cout << "* ";
  cout << endl;
}
The second one is easy also. Instead of outputing * just replace it with j, and you're going to have to add some additional parts. But I'll let you try to figure that out yourself. You'll probably have to use another set of loops.
__________________
...
Xero is offline   Reply With Quote
Old Feb 26th, 2005, 2:31 AM   #3
kent666
Newbie
 
Join Date: Feb 2005
Location: mars
Posts: 2
Rep Power: 0 kent666 is on a distinguished road
Smile

Thanks!!! That was really a great help. Anyway here's the code i use in making this output:
Quote:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
for(a=1;a<=5;a++)
{
 for(b=a;b>=1;b--)
   printf("\t%d",a-b+1);
   printf("\n");
}
for(c=1;c<=4;c++)
{
 for(d=c;d<=4;d++)
   printf("\t%d",d-c+1);
   printf("\n");
}
getch();
}
kent666 is offline   Reply With Quote
Old Feb 26th, 2005, 11:21 AM   #4
Xero
Hobbyist Programmer
 
Join Date: Dec 2004
Location: a cardboard box
Posts: 118
Rep Power: 4 Xero is on a distinguished road
No problem. I just wish life was this simple.
__________________
...
Xero is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:23 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC