Question

In: Computer Science

Write a program in Visual Basics that does the following: Read in 20 numbers, each of...

Write a program in Visual Basics that does the following:

Read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print it only if it is not a duplicate of a number already read. Provide for the “worst case” in which all 20 numbers are different. Use the smallest possible array to solve this problem.

Solutions

Expert Solution

Solution for the above program is provided below. If any doubt please comment below.

Visual Basic Code:

Module Module1

Sub Main()
' Declare variables
Dim value As Integer
Dim str As String
Dim i As Integer
Dim j As Integer
Dim flag As Boolean
' Declare array
Dim arr(20) As Integer
' Read 20 integers
For i = 0 To 19
' Read from input
str = Console.ReadLine()
' Convert to integer
value = CInt(str)
' Check value is between 10 and 100
If value < 10 Or value > 100 Then
i = i - 1
Else
flag = False
' Check the given value is alraedy read
For j = 0 To i
' If alraedy read set flag is true
If (value = arr(j)) Then
flag = True
End If
Next
' If not duplicate print the value
If flag = False Then
Console.WriteLine("Read Value " + CStr(i + 1) + ": " + str)
arr(i) = value
Else
i = i - 1
End If
End If
Next
Console.ReadLine()
End Sub
End Module

Output:


Related Solutions

Using visual studio in MASM x86, Write a program to add the following word size numbers:...
Using visual studio in MASM x86, Write a program to add the following word size numbers: 15F2, 9E89, 8342, 99FF, 7130 using adc instruction and a loop. The result must be in DX, AX. Show the result in debug window.
write a c++ program that prompts a user to enter 10 numbers. this program should read...
write a c++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the two numbers and the average of the 10 numbers PS use file I/o and input error checking methods
Write a program in Easy68K: a) Define an array of numbers in the memory. b) Read...
Write a program in Easy68K: a) Define an array of numbers in the memory. b) Read two numbers from keyboard. The first number is the size of the array and the second number is what index of the array you want to access. The index you entered can be larger than the array. c) Display the element indexed by (index % size) in the array.
C++. Write a program that will read in id numbers and place them in an array.The...
C++. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please enter an...
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
Write a C++ program to read N numbers. Find sum, product, and average of N numbers
Write Visual Basic program that seperates all natural numbers up to 863 value with a comma...
Write Visual Basic program that seperates all natural numbers up to 863 value with a comma side by side and show on the screen Please write readable.Thankss
Write a C++ program that does the following: Read and input file containing the following PersonAName,...
Write a C++ program that does the following: Read and input file containing the following PersonAName, PersonBName, XA,YA, XB, YB where the coordinates of PersonA in a 100 by 100 room is XA, YA and the coordinates of PersonB is XB, YB. Use square root function in cmath sqrt() to calculate the shortest distance between two points. A file will be uploaded in this assignment that will list coordinates of two people. The program should use a function call that...
C++ programming language. Write a program that will read in id numbers and place them in...
C++ programming language. Write a program that will read in id numbers and place them in an array.The array is dynamically allocated large enough to hold the number of id numbers given by the user. The program will then input an id and call a function to search for that id in the array. It will print whether the id is in the array or not. Sample Run: Please input the number of id numbers to be read 4 Please...
Write a C++ program to read a collective of integer numbers. I f the number is...
Write a C++ program to read a collective of integer numbers. I f the number is greater than zero and less than 15 then terminate the loop and find factorial of the number
Write a program that processes numbers, corresponding to student records read in from a file, and...
Write a program that processes numbers, corresponding to student records read in from a file, and writes the required results to an output file (see main ( )). Your program should define the following functions: double read_double (FILE *infile) — Reads one double precision number from the input file. Note: You may assume that the file only contains real numbers. int read_integer (FILE *infile) - Reads one integer number from the input file. double calculate_sum (double number1, double number2, double...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT