In: Computer Science
Im working with visual basics for these problem.
1) Write a program that accepts five integers, and for each integer following the first, prints "GREATER" or "LESS" depending on whether or not the current integer is greater than the previous one. At the end, your application will let user know the largest and the smallest of the five numbers provided
(BONUS): consider using the concepts of swapping the current and previous values as needed and don't use 5 variables.
Program:
Module Module1
Sub Main()
Dim num As Integer
Dim i As Integer
Dim greater, less As Integer
Dim temp As Integer
For i = 1 To 5
Console.Write("Enter Number" & i & ": ")
num = Convert.ToInt32(Console.ReadLine())
If (i = 1) Then
greater = num
less = num
ElseIf (greater < num) Then
greater = num
Console.WriteLine("Greater")
ElseIf (less > num) Then
less = num
Console.WriteLine("Less")
ElseIf greater > less Then
Console.WriteLine("Greater")
Else
Console.WriteLine("Less")
End If
Next i
Console.WriteLine("-----------------------------------" &
vbNewLine)
Console.WriteLine("Largest Number: " & greater)
Console.WriteLine("Smallest Number: " & less)
Console.ReadKey()
End Sub
End Module