Senin, 20 April 2020

SMALL BASIC: Printing stars

Hi, SMALL BASIC programmer, welcome.

In this tutorial, we will discus about variety of printing stars or asteriks.
1. Incremented stars
num_of_row = 10
For i = 0 To num_of_row
  For j = 0 To i
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine("")
EndFor

Output:



2. Reversed incremented (decremented stars)
num_of_row = 10
For i = num_of_row To 0 Step -1
  For j = 0 To i
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine("")
EndFor


 


Or, you can combine step 1 and step 2 into one program, like below:

num_of_row = 10
For round = 0 To 100
For i = 0 To num_of_row
  For j = 0 To i
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine("")
EndFor
'TextWindow.WriteLine("Ok, sukses atas")

Program.delay(1000)
TextWindow.Clear()
For i = num_of_row To 0 Step -1
  For j = 0 To i
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine("")
EndFor
Program.Delay(1000)
TextWindow.Clear()
EndFor


3. The decremented space
num_of_row = 10

For i = 1 To num_of_row
  For j = 1 To num_of_row - i 
    TextWindow.Write("  ")
  EndFor
  For k = 1 To i
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine(" ")
EndFor

Output:



4. The last the increment space
num_of_row = 10

For i = 1 To num_of_row 
  For j = 1 To i
    TextWindow.Write("  ")
  EndFor
  For k = 1 To num_of_row - i 'the rest of colomn
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine(" ")
EndFor

Output:


5. The last, I don't know what to call this, but I call this cool stars
num_of_row = 10

For i = 1 To num_of_row
  For j = 1 To num_of_row - i 
    TextWindow.Write("  ")
  EndFor
  For k = 1 To num_of_row - 1
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine(" ")
EndFor


6. I don't know what to call this, but I call this smooky stars
num_of_row = 10

For i = 1 To num_of_row
  For j = 1 To num_of_row - i 
    TextWindow.Write("  ")
  EndFor
  For k = 1 To j
    TextWindow.Write("* ")
  EndFor
  TextWindow.WriteLine(" ")
EndFor

Tidak ada komentar:

Posting Komentar