![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Oct 2005
Posts: 6
Rep Power: 0
![]() |
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 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 |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: May 2005
Location: Bad Nauheim, Germany
Posts: 436
Rep Power: 4
![]() |
why don't you try to compile it and run it?
__________________
-Steven "Is this a piece of your brain?" - Basil Fawlty |
|
|
|
|
|
#3 | |
|
Newbie
Join Date: Oct 2005
Posts: 6
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
|
|
#4 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
Output for n=5
+ ++ +++ ++++ +++++
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#5 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#6 |
|
Newbie
Join Date: Oct 2005
Posts: 6
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#7 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
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 iFollow the same logic you did in your first try but take what i said in consideration. |
|
|
|
|
|
#8 |
|
Newbie
Join Date: Oct 2005
Posts: 6
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#9 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
Yes, you got it. Now try to understand it very well, this is a good exercise on loops.
|
|
|
|
|
|
#10 |
|
Newbie
Join Date: Oct 2005
Posts: 6
Rep Power: 0
![]() |
Let me just confirm this if n = 12 and print is "*": then it should look like this
* ** *** **** ***** ****** ******* ******** ********* ********** *********** ************ |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|