Compute Whether An Integer Number Is Prime Or Not ?

Feb 28, 2008

What i'm trying to do is compute whether an integer number is prime or not. The program performs this analysis for all odd numbers from 3 up to an input integer limit, for example 100. If the integer in the range 3 to limit is prime, a message stating so is printed. Otherwise, a message is printed that lists at least one other integer divisor. The output for each analyzed number consumes one line of text.

A sample output is shown below:

Limit is 100:
Number 3: is prime
Number 5: is prime
Number 7: is prime

[CODE]...

I understand I need to use loops, boolean functions, vbmath(), strings and multi-line out via concatenation. So I can put this is words how I think it should be done but not so great putting the code together

Test all integers up to the SQRT of the number (100)

limit = math.sqrt(100) + 1

Followed by 1 For statement
For c = 0 to 100 step 2?
And an If statement
If ......
result = false

View 4 Replies


ADVERTISEMENT

Determining If An Integer Entered Is Prime

Mar 22, 2009

i need to alter the code to determine if an integer entered by a user is prime preferably to determine if the number entered (between 1 and 50 is even or odd and prime from 51 to 100) i have the code for listing primes from 51-100 (or whatever range needed)but can i condense the code to a smaller foot print rather than have three different sections for each request

[Code]...

View 3 Replies

Asy Way To Check Whether A Number Is A Prime Number?

Oct 8, 2008

Is there an easy way to check whether a number is a prime number? I've tried doing this:[code] url...

View 3 Replies

Way To Check Whether A Number Is A Prime Number?

Oct 12, 2010

Is there an easy way to check whether a number is a prime number? I've tried doing this:

Code:
Public Function IsPrime(ByVal Input As Integer)
Dim NewInput As Integer

[code].....

View 3 Replies

VB Prime Number Looping

Jan 18, 2010

I've been running through the online "Code Rules" tasks to work through Visual Basic. However I seem to be having a problem with one. The objective is to set a Button Click method to check if any number between 2-5000 is prime or not and to display it in the TextBox if it is prime. Here is what I have so far but it doesn't seem to work.[code...]

View 11 Replies

VB Prime Number Looping?

Mar 2, 2010

I've been running through the online "Code Rules" tasks to work through Visual Basic. However I seem to be having a problem with one. The objective is to set a Button Click method to check if any number between 2-5000 is prime or not and to display it in the TextBox if it is prime. Here is what I have so far but it doesn't seem to work

View 3 Replies

Check Whether An Inputted Number Is Prime?

Sep 9, 2009

I'm working on a console application in VB .net that checks a number that the user has inputted, and tells you whether the number is prime.

The number that has to be inputted has to be between 1 and 100. I have all the code so far and at the moment it can check whether the number is or isn't within the boundries.

View 4 Replies

Determining Prime Number In A Program?

Mar 14, 2012

I just started to use visual basic last month and I only know the basic codes. No matter how hard I try to understand the codes given by the other member, I can't understand it.So the program I'm making is to show all the inputted values and determine the even numbers, the odd numbers and the prime numbers.I don't know how to get the prime numbers.

Private Sub op1_Click()
a = InputBox("Input Endpoint: ")
For x = 1 To a

[code]....

View 1 Replies

Create A Function That Checks If A Number Is A Prime?

May 10, 2011

I've been trying to create a function that checks if a number is a prime. according to [URL]..I have created a function although It doesn't work as expected.

[Code]...

It sometimes returns true for composite numbers. oh and I know if you google it you get functions that do this, but most of them look inefficient so i'm trying to make my own.

View 4 Replies

Get The Prime Number From The User And Give Its Factors?

May 25, 2010

i wrote some code that is suppose to get the prime number from the user and give its factors but there's some error

Dim t As Double
Dim n As Double
Dim ans As Double
Dim exp1 As Double

[code].....

View 2 Replies

Prime Number Checker Unbelievably Slow?

Feb 13, 2011

I have this piece of code which checks whether a given number is prime:

If x Mod 2 = 0 Then
Return False
End If

[code].....

View 8 Replies

Prime Number Output With List In Textbox

Dec 11, 2009

I am not getting an output with a list, I can only get the last number of the statement in a text box.

Dim lowerLimit, upperLimit, primeNumber As Integer
Dim isPrime As Boolean = False
lowerLimit = CType(TextBox1.Text, Integer)
upperLimit = CType(TextBox2.Text, Integer)
While lowerLimit < upperLimit
[Code] .....

View 6 Replies

Make A Prime Number Generator In A Windows Forms Application?

Jan 4, 2010

How do you make a prime number generator in a windows forms application

View 2 Replies

Control The Number Of Decimal Points In Datatable.Compute?

Mar 16, 2009

I am using datatable.comput to calculate the avg of a data column. The data column's datatype = integer, so it returns a integer avg value as well. Can i make it to return double value?

View 3 Replies

Join More Than One Integer Number To One Integer Number?

May 14, 2010

How can I join more than one integer number to become one integer (Long) number?

e.g. 2, 3, 2 and 5 = 2325
123, 7 and 2 = 12372
10, 0, 5 and 1860 = 10051860
0, 10 and 450 = 10450

View 6 Replies

Algorithm - Round An Integer Number?

Jun 10, 2012

How could i round an integer number based on the last digit of the number?
For example:

Dim x As Integer = 12
Dim y As Integer = 139
Dim z As Integer = 2322

[Code].......

View 3 Replies

Check If A Quotient Is A Whole Number Integer?

Oct 31, 2010

I've just begun using VB2008 Express. As practice, I'm trying to create a simple program that allows users to practice their basic arithmetic skills. I've just run into one hiccup.

I have a procedure that generates random numbers for the program to spit out as text that the user will then do arithmetic on. I'm trying to create a loop that checks, in the case that a radio button selecting division practice, that the potential quotient [code]...

View 3 Replies

Dim An Integer In Excel To Create New Number

Oct 11, 2009

I'm trying to create a code to open a new workbook..once it's open I want to save it in numbered order. I have everything else in the code complete except how to finish the integer. I know this should be easy but I'm having a total mind block. [code]

View 1 Replies

Finding The Small Integer Number

Aug 14, 2009

i'm dave mark.. im new to vb 2008.. i just have to have some question.. the problem is i have to input 10 integer number then after inputting the 10 number .. it will compute the sum, average and the smallest.. i have no problem with sum and average but in smallest number only... how to get the smallest number>>?

View 1 Replies

Get A Number From String And Convert It Into An Integer?

Apr 3, 2010

I have a string

12 | Something Special

I would like to cut the "12" and convert into integer (I need it for SQL query purpose)

I tried:

Dim strID As String
strID = "12 | Something Special"
Dim IntStrID As String[code]....

but I tried "" still did not work

View 3 Replies

Get A Random Number From An Integer Array?

Feb 10, 2010

i want to get a random number from an integer array, then delete that number in that array.for example, i have an array like this {1,2,3,4,5,6,7,8,9}now i want to get a RANDOM number in that array ( the number must be in the array), 8 for example. And then delete it from the array.

View 10 Replies

How To Generate Random Number (Integer 1 To 99)

Jun 4, 2012

I know there has to be a simple way to do this but I'm not sure how the syntax would go. I need to generate a random number from 1 to 99. How do I do this? I have my attempt that failed below:

Private Sub LoadBoard()
Dim mynum As Integer = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99)
Storage.Slot1 = mynum(Int(Rnd() * 10 Mod 99))
End Sub

View 11 Replies

Reverse An Integer Number Without Using An Array?

Mar 9, 2010

I just want to know if we can reverse an integer number without using an array

View 3 Replies

Converting Integer Number Into Currency Format?

Jul 12, 2010

How to convert the integer number into currency format in vb.net 2008.

View 4 Replies

Set The Total Number Of Items In Arraylist As An Integer

Nov 16, 2009

When I try to set the total number of items in my arraylist as an integer I get this error:

[Code]...

View 1 Replies

VS 2008 Format Double Number Like Integer?

Aug 2, 2011

How can i format a double number to be like a integer?

for example:

i want to 12.34 to be rounded and displayed like 12 not 12.0.

because when i do String.Format("{0:n0}", 12.34) the number will be displayed as 12.0

View 3 Replies

Way Of Testing To See If Number Variable Is Integer Or A Decimal?

Jul 19, 2011

Is there a way of testing to see if a number variable is an integer, or a decimal?

View 8 Replies

What String Format Use For The Double Or Integer Number

Feb 7, 2012

The problem i m facing is that i m getting all numbers in this format

1- if it is double then 123.45

2- if it is integer then 123.00 which is wrong

how to format a number wether it is in decimal or integer.if it is decimal then something like 123.56 or if it is integer then 123 not 123.00.Tell me the generalized string function and how to use it..

View 6 Replies

Forms :: Validate Each Textbox So The Number Entered Is An Integer?

May 11, 2009

I have designed a form with textboxes for numerical entry. I need to validate each textbox so the number entered is an integer, and is between 0-1000. I am struggling to find how to validate the data entry.

View 4 Replies

VB 2010 - Unwanted Rounding To Nearest Integer (Whole Number)

Apr 28, 2011

I have a program that will round any numbers I give it regardless of the data type I set (I've tried double and decimal) before it saves into the DB. I'm using MS access for the DB and I've set the data types in access to Numeric Double, Numeric Decimal, and Currency and all with decimal places set to 4 -- all to no avail.

What I do know:
1) The textboxes on the form accept the number value as I enter it and after I hit save the value displayed is the same as the number that I entered. However, once I query the database again for that entry the value has been rounded up/down to the nearest integer (whole number). For example: I enter 1000.50 and hit save. I search for that same entry and the value is saved as 1000. If I enter 1000.51 and hit save then search for the entry it shows the value saved as 1001.

2) I can store the desired value directly into the DB by manually entering it. When I search for that entry from within the program it displays the correct amount. HOWEVER, if I try to change the amount and then hit save I get a concurrency violation.

I think that it may be a setting somewhere in the program that doesn't allow for decimal places but I've search everywhere and I cant find anything.

View 7 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved