a.abdullah a.abdullah - 1 month ago 19
Vb.net Question

I need help (Visual Basic)

Write a program that reads 3 integers numbers, then the program prints the square and cube of each.

enter image description here

This answer in array I want to answer in random please.

Dim NumOfIntegers() As Integer = {1, 2, 3, 4, 8}
Dim x, y As Integer
For Each num As Integer In NumOfIntegers
x = num ^ 2
y = num ^ 3
MessageBox.Show("Square Of " & num & " = " & x & vbCrLf & "Cube Of " & num & " = " & y)
Next

Answer

This Code fills a Integer List with 3 different random numbers between 1 and 100

Dim NumOfIntegers As New List(Of Integer)

While NumOfIntegers.Count < 3
    Dim i As Integer = CInt(Math.Ceiling(Rnd() * 100)) + 1
    If Not NumOfIntegers.Contains(i) Then NumOfIntegers.Add(i)
End While

NumOfIntegers.Sort()

Dim x, y As Integer    
For Each num As Integer In NumOfIntegers
    x = num ^ 2
    y = num ^ 3
    MessageBox.Show("Square Of " & num & " = " & x & vbCrLf & "Cube Of " & num & " = " & y)
Next

Code if you only want to use a for loop:

(It´s untested code and within the 3 Integers might be duplicates)

Dim NumOfIntegers() As New Integer = {(CInt(Math.Ceiling(Rnd() * 100)) + 1), (CInt(Math.Ceiling(Rnd() * 100)) + 1), (CInt(Math.Ceiling(Rnd() * 100)) + 1)}

Dim x, y As Integer    
For Each num As Integer In NumOfIntegers
    x = num ^ 2
    y = num ^ 3
    MessageBox.Show("Square Of " & num & " = " & x & vbCrLf & "Cube Of " & num & " = " & y)
Next
Comments