tags:

views:

48

answers:

4

how do i display the following:

Q1)1    Q2)1AAAA
   00      12BBB
   111     123CC
   0000    1234D
   11111
+1  A: 
MessageBox.Show("Q1)1 Q2)1AAAA 00 12BBB 111 123CC 0000 1234D 11111")

Please explain what you need the loop(s) to do. Also please show your code so far so we can help.

EDIT

Ok the various output lines make more sense now in your question. However it would still be useful and recommended to post your code thus far, so we can help point you in the right direction.

(Glad to help but aren't here to write everything for you.)

JYelton
You mean MessageBox.Show("Q1)1 Q2)1AAAA 00 12BBB 111 123CC 0000 1234D 11111") as he wants VB.NET not C# :)
Wayne
Ah, true indeed. Thanks I will edit it accordingly!
JYelton
Won't work alas, the initial formatting was wrong.
Gamecat
A: 

Q1:

  • make an outer loop from 1 to 5 (i).
  • make an inner loop from 1 to i (j).
  • if i is odd, add 1 else 0 to a string and write it at the end of the inner loop. (and clear it).

Q2:

  • make an outer loop from 1 to 4 (i).
  • make an inner loop from 1 to i (j).
  • add the number j to a temp string.
  • add 5-i times the character X(i) where X(1) = A, X(2) = B etc.
  • print and clear the string before the next iteration of the outer loop.
Gamecat
A: 

Pseudo-code only, since this smells suspiciously like homework :-)

Number 1:

string s1, s2         or shifty version:  string s
integer i, j                              integer i,j,k
s1 = "1"                                  k = 0
for i = 1 to 5                            for i = 1 to 5
    s2 = ""                                   s = ""
    for j = 1 to i                            for j = 1 to i
        s2 = s2 + s1                              s = s + chr(k+30)
    endfor                                    endfor
    output s2                                 output s
    if s1 = "1" then                          k = 1 - k
        s1 = "0"                          endfor
    else
        s1 = "1"
    endif
endfor

Number 2:

string s
integer i, j
for i = 1 to 4
    s = ""
    for j = 1 to i
        s = s + chr(j+30)
    endfor
    for j = i+1 to 5
        s = s + chr(i+64)
    endfor
    output s
endfor
paxdiablo
A: 

No need for inner and outer loop. This will do it:
Q1:

    For p As Integer = 1 To 5
        MsgBox("".PadRight(p, CChar((p Mod 2).ToString)))
    Next

Q2:

    Dim pre As String = ""
    For p As Integer = 0 To 3
        pre &= (p + 1).ToString
        MsgBox(pre & "".PadRight(4 - p, CChar(Chr(65 + p))))
    Next

PS. Please tell us your teachers reaction to "your" solution. ;)

Stefan