Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do I create Floyd\'s Triangle using Visual Basic? In addition, I only want t

ID: 3697742 • Letter: H

Question

How do I create Floyd's Triangle using Visual Basic? In addition, I only want to display even numbers starting from 2.

Example:

---- 2

--4 ---6

8 -10 -12

The dashes represents spaces.

(Resembles Pascals Triangle)

I have done some coding:

Module Module1
Sub Main()
Dim i, j, s, n As Integer
s = 2
For i = 1 To 250
For j = 1 To i
Console.Write(" " & s)
s += 2
Next
Console.WriteLine()
Console.ReadLine()
Next
Console.ReadLine()
End Sub
End Module

However my code creates a triangle that looks more like this:

2

4 6

8 10 12

14 16 18 20

Explanation / Answer

Module floyds_triangleinvb Sub Main() Dim i, j, s, n As Integer Console.Write("Please Enter the number of lines you want to print:") n = CInt(Console.ReadLine()) s = 2 For i = 2 To n // starting from second row containing 2 For j = 1 To i Console.Write(s & " ") s += 2 // to print all the even numbers Next Console.WriteLine() Next Console.ReadLine() End Sub End Module

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote