Question

In: Computer Science

Use VB.net to create a loop that posts the first 100 prime numbers. Then, write code...

Use VB.net to create a loop that posts the first 100 prime numbers. Then, write code to confirm the numbers are prime.

Solutions

Expert Solution

1. CODE TO GENERATE FIRST 100 PRIME NUMBERS:

Imports System

Public Class Test
Public Shared Sub Main()
Dim num, i, j as Integer
Dim b as Boolean
num = 3
b = True
System.Console.WriteLine("Prime number from 1 to 100")
System.Console.WriteLine("2")
For i = 2 To 542
b = true
For j = 2 To Math.Sqrt(num)
If num Mod j = 0 Then
b = False
GoTo Break
End If
Next
  
break:
If b Then
System.Console.WriteLine(num)
End If
num = num + 1
b = True
Next

System.Console.ReadKey()
  
End Sub
End Class

OUTPUT:

2. CODE TO CONFIRM THE USER INPUT NUMBERS ARE PRIME:

Imports System

Public Class Test
Public Shared Sub Main()
Dim primeI, primeN as Integer
Dim primeFlag as Boolean
primeN = Int32.Parse(Console.ReadLine())
  
primeFlag = True
  
For primeI = 2 To primeN/2
If primeN Mod primeI = 0 Then
primeFlag = False
End If
Next
  
If primeFlag Then
System.Console.WriteLine("It is prime")
Else
System.Console.WriteLine("It is not prime")
End If
  
End Sub
End Class


Related Solutions

(Use the GenericStack class) Write a program that displays the first 100 prime numbers in descending...
(Use the GenericStack class) Write a program that displays the first 100 prime numbers in descending order. Use a stack to store the prime numbers.
write a code using c++. Find the first 10 prime numbers and store them in an...
write a code using c++. Find the first 10 prime numbers and store them in an array.
Part 2 Write a C code to create 5 random numbers between 90 and 100 (included)...
Part 2 Write a C code to create 5 random numbers between 90 and 100 (included) and print the values on the screen. Part 3 Create a function that will mimic throwing the dice twice. The function will do the following when you call it. The function will generate 2 random numbers between 1 and 6 The function will display the two random numbers to the user The function will display “Winner” if the sum of the two numbers are...
Question : Write a C++ program to find all prime numbers between 10 to 100 by...
Question : Write a C++ program to find all prime numbers between 10 to 100 by using while loop. Hint: a prime number is a number that is divisible by 1 and itself. For example 3, 5, 7, 11, 13 are prime numbers because they are only divisible by 1 and themselves.
Write an assembly program (Data and Code) that uses loop to read 10 numbers and output...
Write an assembly program (Data and Code) that uses loop to read 10 numbers and output the largest of those numbers, you can assume any length for those numbers. 80x86 assembly language
Java Class Create a class with a main method. Write code including a loop that will...
Java Class Create a class with a main method. Write code including a loop that will display the first n positive odd integers and compute and display their sum. Read the value for n from the user and display the result to the screen.
VISUAL STUDIO CODE Use a for loop for to create "password". Request the password at least...
VISUAL STUDIO CODE Use a for loop for to create "password". Request the password at least 3 times. If the password is 12345, the procedure ends, if the correct password entered, close excel saving changes. THANKS
Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100...
Write an Arduino code that does the following. Generate 50 random numbers between the numbers 100 and 300. Pick a number at random out of these 50 random variables. a. Determine the probability of the chosen number being greater than 200. This may be achieved by counting the numbers that are greater than 200 and dividing the count by 50. Make sure you, i.Formulate the appropriate if-conditions to check for a number being greater than 200 ii. Use a for-loop...
• In this script, write MATLAB code to create an array A of size 100 ×...
• In this script, write MATLAB code to create an array A of size 100 × 3. The first column should contain random numbers between 0 and 10. The second column should also contain random numbers between 0 and 10. The third column should contain random integers between 20 and 50. The first two columns represent the x and y coordinates of a map, respectively. The third column represents the height of buildings. For example, if the first row of...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number from 1 to 10 thousand and keeps updating a count variable (count variable starts at 0 ) according to these rules: n1 = 14 n2 = 54 n3 = 123 if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT