Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Oct 4th, 2005, 4:09 AM   #1
Worried newbie
Newbie
 
Join Date: Oct 2005
Posts: 6
Rep Power: 0 Worried newbie is on a distinguished road
Unhappy Please help

I have just recently started college and with it started using vb6 for the first time, recently i was given a task to do but because i have little or no experience with this im really worried because i have become so worried about the problem that my brain wont allow me to think about it without panicing....

What shape will be displayed by the following vb program for any value of n>1?
for i = 1 to n
for j = 1 to i
print "+";
next j
print
next i

Im sure this is very easy but i sit here pen in hand cunfused and realy worried

Im not looking for the answer but an understandable explanaition and an example of my problem so i can do it myself

Thankyou for any help
Worried newbie is offline   Reply With Quote
Old Oct 4th, 2005, 5:31 AM   #2
stevengs
Professional Programmer
 
stevengs's Avatar
 
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4 stevengs is on a distinguished road
why don't you try to compile it and run it?
__________________
-Steven
"Is this a piece of your brain?" - Basil Fawlty
stevengs is offline   Reply With Quote
Old Oct 4th, 2005, 5:35 AM   #3
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
Output for n=5
+
++
+++
++++
+++++
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Oct 4th, 2005, 5:36 AM   #4
Worried newbie
Newbie
 
Join Date: Oct 2005
Posts: 6
Rep Power: 0 Worried newbie is on a distinguished road
Quote:
Originally Posted by stevengs
why don't you try to compile it and run it?
Im not aloud to do that, i have to do it on paper.
Worried newbie is offline   Reply With Quote
Old Oct 4th, 2005, 10:48 AM   #5
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
then run it on the paper. Pick a value for n, say n = 3 and go thru the loop one iteration at a time and record the output everytime you encounter a "print" statement.
OpenLoop is offline   Reply With Quote
Old Oct 4th, 2005, 1:01 PM   #6
Worried newbie
Newbie
 
Join Date: Oct 2005
Posts: 6
Rep Power: 0 Worried newbie is on a distinguished road
I have had a go and come out with three different out comes.

First is
1
12
123
1234
12345

second is
1
23
345
4567
56789

Third is
1
23
345
4567
56789

They were n=5..... now in really confused but i think one is correct?
Worried newbie is offline   Reply With Quote
Old Oct 4th, 2005, 1:08 PM   #7
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
If you where printing j the first one will be correct for n=5. But look at the code closely, what are you printing?
for i = 1 to n
  for j = 1 to i
      print "+";
  next j
  print
next i
You're printing "+" for every iteration of the nested loop(the one with j) and a new line for every iteration of the i loop.
Follow the same logic you did in your first try but take what i said in consideration.
OpenLoop is offline   Reply With Quote
Old Oct 4th, 2005, 1:19 PM   #8
Worried newbie
Newbie
 
Join Date: Oct 2005
Posts: 6
Rep Power: 0 Worried newbie is on a distinguished road
Ok so im trying to think, if n = 10 it would look like this
+
++
+++
++++
+++++
++++++
+++++++
++++++++
+++++++++
++++++++++

I know this must seem so easy to some people but it can be very confusing to a first time user so thanx a lot for all the help
Worried newbie is offline   Reply With Quote
Old Oct 4th, 2005, 1:20 PM   #9
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Yes, you got it. Now try to understand it very well, this is a good exercise on loops.
OpenLoop is offline   Reply With Quote
Old Oct 4th, 2005, 1:23 PM   #10
Worried newbie
Newbie
 
Join Date: Oct 2005
Posts: 6
Rep Power: 0 Worried newbie is on a distinguished road
Let me just confirm this if n = 12 and print is "*": then it should look like this
*
**
***
****
*****
******
*******
********
*********
**********
***********
************
Worried newbie 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:07 AM.

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