COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Prime numbers

• Email
• Follow

```Hello

I need to write a program, that takes a number (entered into a textbox,
by the user) and determines if the number is prime or not.  If the
number is a prime number, then the program is just supposed to display,
something like "This is a prime number" in a label. If the number
entered is not a prime number, then the program is supposed to display
the prime factors of that number. If you are not familiar with prime
numbers and/or prime factors, there is a explanation of them below.
Must use the following Function and Procedure in program:
A function that takes a single Integer parameter and returns a boolean
value. True if the parameter is prime, False otherwise.
A procedure that takes an Integer parameter and computes and writes out
the prime factors of that parameter.

Prime numbers are numbers that can only be divided evenly by 1 and the
number itself. For example, 7 is a prime number since there is no
number less than 7 (except for 1) that divides evenly into it.

Numbers that are not prime numbers can be reduced to a product of prime
factors. For example 15 is not a prime number but it can be expressed
as (3 * 5) i.e. as set of prime numbers multiplied together. Note that
a prime factor may occur more than once. For example 16 is 2 * 2 * 2 *
2.

problem?

Thanks.

```
 0
Reply aronb2005 (16) 12/1/2005 12:13:29 AM

See related articles to this posting

```Its not too hard to do but it sounds like a homework question.  If it is a
homework question you would be better off struggling through the problem

Post the code you have done and where you are having trouble, then some
could help..

You will be a better programmer in the long run struggling through problems
like this.

--
Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--

"new programer" <aronb2005@gmail.com> wrote in message
> Hello
>
> I need to write a program, that takes a number (entered into a textbox,
> by the user) and determines if the number is prime or not.  If the
> number is a prime number, then the program is just supposed to display,
> something like "This is a prime number" in a label. If the number
> entered is not a prime number, then the program is supposed to display
> the prime factors of that number. If you are not familiar with prime
> numbers and/or prime factors, there is a explanation of them below.
> Must use the following Function and Procedure in program:
> A function that takes a single Integer parameter and returns a boolean
> value. True if the parameter is prime, False otherwise.
> A procedure that takes an Integer parameter and computes and writes out
> the prime factors of that parameter.
>
> Prime numbers are numbers that can only be divided evenly by 1 and the
> number itself. For example, 7 is a prime number since there is no
> number less than 7 (except for 1) that divides evenly into it.
>
> Numbers that are not prime numbers can be reduced to a product of prime
> factors. For example 15 is not a prime number but it can be expressed
> as (3 * 5) i.e. as set of prime numbers multiplied together. Note that
> a prime factor may occur more than once. For example 16 is 2 * 2 * 2 *
> 2.
>
> problem?
>
> Thanks.
>

```
 0
Reply NOSPAMinveign (139) 12/1/2005 12:37:52 AM

```The last one was 'fibonacci', now it's 'Prime Numbers'. It's far far far
better in the long run to do home work with the DIY method. If you don't
know that method, just ask anybody that's over 25.

"new programer" <aronb2005@gmail.com> wrote in message
> Hello
>
> I need to write a program, that takes a number (entered into a textbox,
> by the user) and determines if the number is prime or not.  If the
> number is a prime number, then the program is just supposed to display,
> something like "This is a prime number" in a label. If the number
> entered is not a prime number, then the program is supposed to display
> the prime factors of that number. If you are not familiar with prime
> numbers and/or prime factors, there is a explanation of them below.
> Must use the following Function and Procedure in program:
> A function that takes a single Integer parameter and returns a boolean
> value. True if the parameter is prime, False otherwise.
> A procedure that takes an Integer parameter and computes and writes out
> the prime factors of that parameter.
>
> Prime numbers are numbers that can only be divided evenly by 1 and the
> number itself. For example, 7 is a prime number since there is no
> number less than 7 (except for 1) that divides evenly into it.
>
> Numbers that are not prime numbers can be reduced to a product of prime
> factors. For example 15 is not a prime number but it can be expressed
> as (3 * 5) i.e. as set of prime numbers multiplied together. Note that
> a prime factor may occur more than once. For example 16 is 2 * 2 * 2 *
> 2.
>
> problem?
>
> Thanks.
>

```
 0
Reply Ivar.ekstromer000 (307) 12/1/2005 12:52:10 AM

```Why don't you just write out those prime numbers that you know and determine the "pattern" so that
you can create the algorithm that generates prime numbers.  Computers are a tool that can save the
user time, but you have to "tell" that tool what to do.  If you don't learn how to use it now, you
won't know later on either.  We will help you, but we won't do it for you.  Show us your code.

Jim Y

"new programer" <aronb2005@gmail.com> wrote in message
> Hello
>
> I need to write a program, that takes a number (entered into a textbox,
> by the user) and determines if the number is prime or not.  If the
> number is a prime number, then the program is just supposed to display,
> something like "This is a prime number" in a label. If the number
> entered is not a prime number, then the program is supposed to display
> the prime factors of that number. If you are not familiar with prime
> numbers and/or prime factors, there is a explanation of them below.
> Must use the following Function and Procedure in program:
> A function that takes a single Integer parameter and returns a boolean
> value. True if the parameter is prime, False otherwise.
> A procedure that takes an Integer parameter and computes and writes out
> the prime factors of that parameter.
>
> Prime numbers are numbers that can only be divided evenly by 1 and the
> number itself. For example, 7 is a prime number since there is no
> number less than 7 (except for 1) that divides evenly into it.
>
> Numbers that are not prime numbers can be reduced to a product of prime
> factors. For example 15 is not a prime number but it can be expressed
> as (3 * 5) i.e. as set of prime numbers multiplied together. Note that
> a prime factor may occur more than once. For example 16 is 2 * 2 * 2 *
> 2.
>
> problem?
>
> Thanks.
>

```
 0
Reply j.s.yablonsky1 (192) 12/1/2005 2:23:48 AM

```"new programer" <aronb2005@gmail.com> wrote in message
> Hello
>
> Must use the following Function and Procedure in program:
> A function that takes a single Integer parameter and returns a boolean
> value. True if the parameter is prime, False otherwise.
> A procedure that takes an Integer parameter and computes and writes out
> the prime factors of that parameter.
>
> Prime numbers are numbers that can only be divided evenly by 1 and the
> number itself. For example, 7 is a prime number since there is no
> number less than 7 (except for 1) that divides evenly into it.
>

As stated, you get to do your own homework. Here are some hints on getting on
with it.

Tackle one problem at a time. Do the function first; don't even think about the
second part till that part is done.

Test often, writing something that for now just says "Prime" or "Not Prime".

Set up the function, which is "A function that takes a single Integer parameter
and returns a boolean value."

Given the number to test, how will you decide whether to return true or false?

"Prime numbers are numbers that can only be divided evenly by 1 and the
number itself."

What visual basic statement might you use to run a test For every X from 1 To
Something?

To test for even division, you will probably need to first *do* the division.
There are various ways of then determining whether the result is a whole number
or not.

```
 0
Reply mynamehere (1583) 12/1/2005 2:28:49 AM

```I am not asking for the whole answer to the problem, I am just asking
for help with figuring out a certain part. I understand the algorithm
or pseudo code of the problem, but can not translate to VB code. I have
looked through my notes, textbook and Internet tutorials or lessons, to
try and figure it out, and have been unsuccessful. The part, I do not
understand right now, is the main part, which is to determine whether a
number is prime or not. I see that a number is prime, if it is not
evenly divisible. But how do I determine or test whether a number is
evenly divisble or not. (9/3=3) (4/2=2) (10/5=2). Would I use 'mod' or
'division' to determine even divisibility?

```
 0
Reply aronb2005 (16) 12/1/2005 7:09:11 AM

```In response to the post:
On 30 Nov 2005 23:09:11 -0800, "new programer" <aronb2005@gmail.com>
stated...and I replied:

>for help with figuring out a certain part. I understand the algorithm
>or pseudo code of the problem, but can not translate to VB code. I have
>looked through my notes, textbook and Internet tutorials or lessons, to
>try and figure it out, and have been unsuccessful. The part, I do not
>understand right now, is the main part, which is to determine whether a
>number is prime or not. I see that a number is prime, if it is not
>evenly divisible. But how do I determine or test whether a number is
>evenly divisble or not. (9/3=3) (4/2=2) (10/5=2). Would I use 'mod' or
>'division' to determine even divisibility?
>
>
>
>

Good question to get this thing started.  To determine if a number is
evenly divisable you can test the raw result with a forced integer.
Such as the result from the Int() function.  But, be careful of the
numeric type you're using.  If you define your variables as "Integer"
the result with ALWAYS be Integer (No fractions).  So, you must define
your variables as a type that allow fractional values (Like Single or
Double).

then try this:

Dim dblX As Double, dblY As Double

dblX = 9 / 3
dblY = Int(9 / 3)
If dblX = dblY Then
Print "Divided evenly"
Else
Print "Not divided evenly"
End If

Note:  This is "fluffed code", in other words it could have been
written much smaller and more effeciently but was written this way for
example purposes.

Hope this helps
Shell
```
 0
Reply drshell (107) 12/1/2005 7:58:48 AM

```"new programer" <aronb2005@gmail.com> wrote in message
| I am not asking for the whole answer to the problem, I am just
| for help with figuring out a certain part. I understand the
algorithm
| or pseudo code of the problem, but can not translate to VB code. I
have
| looked through my notes, textbook and Internet tutorials or lessons,
to
| try and figure it out, and have been unsuccessful. The part, I do
not
| understand right now, is the main part, which is to determine
whether a
| number is prime or not. I see that a number is prime, if it is not
| evenly divisible. But how do I determine or test whether a number is
| evenly divisble or not. (9/3=3) (4/2=2) (10/5=2). Would I use 'mod'
or
| 'division' to determine even divisibility?
|
|
|
|
|

Erm, consider that the MOD function, if not equal to zero, is a simple
and reliable test to determine divisibility of one whole number by
another.  Also, consider that any number greater than 1/2 of the
"target" number-1 need not be checked for divisibility into the
"target" number, e.g., if the target number is 1001 (remember we know
2 is the only prime number that is even, thus all prime numbers are
odd except for 2), you can start testing at 2 and finish at
(1001-1)/2, since whole numbers > 500 will not be divisible evenly
into 1001.

I don't think you actually understand the algorithm or pseudo code or
it would literally jump off the page at you as to how easy this
project is to code.  Keep trying, look at how to use a For/Next Loop
and how you to establish the starting and ending values for the loop.
Also, consider altering the increment value in a for/next loop.  Any
more help and I'd be writing the code for you.
--
Best regards,
Kyle

```
 0
Reply me4 (19675) 12/1/2005 8:00:45 AM

```"new programer" <aronb2005@gmail.com> wrote in
> for help with figuring out a certain part. I understand the algorithm
> or pseudo code of the problem, but can not translate to VB code. I have
> looked through my notes, textbook and Internet tutorials or lessons, to
> try and figure it out, and have been unsuccessful. The part, I do not
> understand right now, is the main part, which is to determine whether a
> number is prime or not. I see that a number is prime, if it is not
> evenly divisible. But how do I determine or test whether a number is
> evenly divisble or not. (9/3=3) (4/2=2) (10/5=2). Would I use 'mod' or
> 'division' to determine even divisibility?

assign the result of the divistion to a variable defined as Single or
Double, not Integer. Doing so, the result can hold a fractinal part, for
example 5/3 = 1.6666.

Then check if there is a fractional part in it, meaning that the numbers are
not "even divisible":
if x - Fix(x) <> 0 Then....

--

Heinrich
http://www.gartrip.de
mail: new<at>gartrip.de

```
 0
Reply nws5591 (30) 12/1/2005 8:01:28 AM

```"new programer" <aronb2005@gmail.com> wrote in message
>IThe part, I do not
> understand right now, is the main part, which is to determine whether a
> number is prime or not. I see that a number is prime, if it is not
> evenly divisible. But how do I determine or test whether a number is
> evenly divisble or not.

In addition to using Fix or Int to see if a floating point quotient has a
fractional part (the approach in the other posts), you can also use just
integers, and test to see if multiplying recreates the original number:

i = Original \ TestInt    ' \ is integer division

Then ask, is i * TestInt = Original?

```
 0
Reply mynamehere (1583) 12/1/2005 9:11:25 AM

```"Kyle" <me@privacy.net> wrote in message
news:U8WdnU8lhIs5MBPeRVn-ug@comcast.com...
> "new programer" <aronb2005@gmail.com> wrote in message
> Also, consider that any number greater than 1/2 of the
> "target" number-1 need not be checked for divisibility into the
> "target" number, e.g., if the target number is 1001 (remember we know
> 2 is the only prime number that is even, thus all prime numbers are
> odd except for 2), you can start testing at 2 and finish at
> (1001-1)/2, since whole numbers > 500 will not be divisible evenly
> into 1001.
>

Actually, you don't need to test a number larger than the square root of the
target, since any number larger that was evenly divisible would have a "partner"
number that was smaller. In the case of 1001, checking up to 31 is sufficent.

```
 0
Reply mynamehere (1583) 12/1/2005 9:15:31 AM

```> Erm, consider that the MOD function, if not equal to zero, is a
simple
> and reliable test to determine divisibility of one whole number by
> another.  Also, consider that any number greater than 1/2 of the
> "target" number-1 need not be checked for divisibility into the
> "target" number, e.g., if the target number is 1001 (remember we
know
> 2 is the only prime number that is even, thus all prime numbers are
> odd except for 2), you can start testing at 2 and finish at
> (1001-1)/2, since whole numbers > 500 will not be divisible evenly
> into 1001.

Actually, you can stop looking when you reach the square root of the
number. For 1001 (whose square root is 31.638584+), if no prime less
than or equal to 31 divides it, then it is prime... you don't have to
look at any larger numbers.

Rick

```
 0
Reply rickNOSPAMnews (2145) 12/1/2005 9:28:54 AM

```new programer wrote:
> But how do I determine or test
> whether a number is evenly divisble or not. (9/3=3D3) (4/2=3D2) =
(10/5=3D2).
> Would I use 'mod' or 'division' to determine even divisibility?

What you first need to know is if it's evenly divisible by 2, since no =
even number except 2 is prime.  You can do this very quickly for integer =
values by testing the underlying bit pattern. I know this is a little =
advanced for a first project, but it's a glimpse at how the same problem =
can be approached in different ways. So, for values > 2...

If (MyInteger And 1) =3D 0 Then
' MyInteger is even, so it's not prime

This is equivalent to, but much faster than:

If (MyInteger Mod 2) =3D 0 Then

--=20

Jim Mack
MicroDexterity Inc
www.microdexterity.com

```
 0
Reply jmack (266) 12/1/2005 11:39:15 AM

```"new programer" <aronb2005@gmail.com> wrote in message
> Hello
>
> I need to write a program, that takes a number (entered into a textbox,
> by the user) and determines if the number is prime or not.  If the
> number is a prime number, then the program is just supposed to display,
> something like "This is a prime number" in a label. If the number
> entered is not a prime number, then the program is supposed to display
> the prime factors of that number. If you are not familiar with prime
> numbers and/or prime factors, there is a explanation of them below.
> Must use the following Function and Procedure in program:
> A function that takes a single Integer parameter and returns a boolean
> value. True if the parameter is prime, False otherwise.
> A procedure that takes an Integer parameter and computes and writes out
> the prime factors of that parameter.
>
> Prime numbers are numbers that can only be divided evenly by 1 and the
> number itself. For example, 7 is a prime number since there is no
> number less than 7 (except for 1) that divides evenly into it.
>
> Numbers that are not prime numbers can be reduced to a product of prime
> factors. For example 15 is not a prime number but it can be expressed
> as (3 * 5) i.e. as set of prime numbers multiplied together. Note that
> a prime factor may occur more than once. For example 16 is 2 * 2 * 2 *
> 2.
>
> problem?

```
 0
Reply usenetmeister (427) 12/1/2005 11:39:54 AM

```"Rick Rothstein [MVP - Visual Basic]"
<rickNOSPAMnews@NOSPAMcomcast.net> wrote in message
news:ZIWdnckX1vrKXxPenZ2dnUVZ_tOdnZ2d@comcast.com...
| > Erm, consider that the MOD function, if not equal to zero, is a
| simple
| > and reliable test to determine divisibility of one whole number by
| > another.  Also, consider that any number greater than 1/2 of the
| > "target" number-1 need not be checked for divisibility into the
| > "target" number, e.g., if the target number is 1001 (remember we
| know
| > 2 is the only prime number that is even, thus all prime numbers
are
| > odd except for 2), you can start testing at 2 and finish at
| > (1001-1)/2, since whole numbers > 500 will not be divisible evenly
| > into 1001.
|
| Actually, you can stop looking when you reach the square root of the
| number. For 1001 (whose square root is 31.638584+), if no prime less
| than or equal to 31 divides it, then it is prime... you don't have
to
| look at any larger numbers.
|
| Rick
|

Ack, my brain cells were obviously near comotose when I typed my post
(late night mathematical analysis was never my forte, that's my excuse
and I'm sticking to it!), thx to those for reminding me of the simple
math constructs involved here.  I'm ashamed to admit that I am an
electrical engineer now.

--
Best regards,
Kyle
|

```
 0
Reply me4 (19675) 12/2/2005 2:58:09 PM

```Thanks for trying to help me guys. Ok, so I understand that there is no
even prime number, besides 2. And also if, you mod any even number by
2, the result will obviously be 0. But then, how do I deal with
composite (non prime) numbers, that are odd.

I have come up with the following algorithm so far:
If inputNum Mod 2 = 0 Then (for even non prime numbers)
' not prime
elsif inputNum mod ?? = ?? Then (for odd non prime numbers)
' not prime
else (for prime numbers)
' number is prime

```
 0
Reply aronb2005 (16) 12/7/2005 12:16:55 AM

```new programer wrote:
> Thanks for trying to help me guys. Ok, so I understand that there is no
> even prime number, besides 2. And also if, you mod any even number by
> 2, the result will obviously be 0. But then, how do I deal with
> composite (non prime) numbers, that are odd.
>
> I have come up with the following algorithm so far:
> If inputNum Mod 2 = 0 Then (for even non prime numbers)
> ' not prime
> elsif inputNum mod ?? = ?? Then (for odd non prime numbers)
> ' not prime
> else (for prime numbers)
> ' number is prime
>
>
>
>
>
I believe that any number that is not prime can be divided by either two
or three. If you factor a number to the smallest factors you will (I
think) always have either a 2 or 3 in the list of factors unless it is
prime or the square of a prime. Someone who is more steeped in math will
correct me if I'm wrong. So If my postulate is correct then...

isPrime = False
If inputNum Mod 2 and _
inputNum Mod 3 and _
sqr(inputNum) not an Integer then
isPrime = True
End If

--
Steve Kelley
Protean Instrument Corp.
```
 0
Reply skelley (70) 12/7/2005 1:31:50 PM

```> I believe that any number that is not prime can be divided by either
two
> or three. If you factor a number to the smallest factors you will (I
> think) always have either a 2 or 3 in the list of factors unless it
is
> prime or the square of a prime. Someone who is more steeped in math
will
> correct me if I'm wrong. So If my postulate is correct then...

You are incorrect. For example, 35 is not prime... it is only
divisible by 5 and 7, so it would fail your divisible by 2 or 3 test.
And no matter how many numbers you attempt to add to your testing, I
can always produce a composite (non-prime) number that has different
divisors... I will just take any two or more prime numbers not on your
list and multiply them together.

Rick

```
 0
Reply rickNOSPAMnews (2145) 12/7/2005 2:02:34 PM

```Steve Kelley wrote:
> new programer wrote:
>
>> Thanks for trying to help me guys. Ok, so I understand that there is no
>> even prime number, besides 2. And also if, you mod any even number by
>> 2, the result will obviously be 0. But then, how do I deal with
>> composite (non prime) numbers, that are odd.
>>
>> I have come up with the following algorithm so far:
>> If inputNum Mod 2 = 0 Then (for even non prime numbers)
>> ' not prime
>> elsif inputNum mod ?? = ?? Then (for odd non prime numbers)
>> ' not prime
>> else (for prime numbers)
>> ' number is prime
>>
>>
>>
>>
>>
> I believe that any number that is not prime can be divided by either two
> or three. If you factor a number to the smallest factors you will (I
> think) always have either a 2 or 3 in the list of factors unless it is
> prime or the square of a prime. Someone who is more steeped in math will
> correct me if I'm wrong. So If my postulate is correct then...
>
> isPrime = False
> If inputNum Mod 2 and _
>     inputNum Mod 3 and _
>     sqr(inputNum) not an Integer then
>     isPrime = True
> End If
>

I amend my post. Obviously, a number can be many powers of a prime
without being divisible by 2 or 3. For example 7^3 = 343 so instead of
testing inputNum to see if it is the square of a prime one has to look
to see if it is some power of a prime which is much more difficult. The
test for 2 and 3 will find most non primes but the sqr(inputNum) is of
no help really. I don't have a simple solution.

I'm dealing with a sinus headache at the moment and am not thinking
straight.

--
Steve Kelley
Protean Instrument Corp.
```
 0
Reply skelley (70) 12/7/2005 2:17:29 PM

```Rick Rothstein [MVP - Visual Basic] wrote:
>>I believe that any number that is not prime can be divided by either
>
> two
>
>>or three. If you factor a number to the smallest factors you will (I
>>think) always have either a 2 or 3 in the list of factors unless it
>
> is
>
>>prime or the square of a prime. Someone who is more steeped in math
>
> will
>
>>correct me if I'm wrong. So If my postulate is correct then...
>
>
> You are incorrect. For example, 35 is not prime... it is only
> divisible by 5 and 7, so it would fail your divisible by 2 or 3 test.
> And no matter how many numbers you attempt to add to your testing, I
> can always produce a composite (non-prime) number that has different
> divisors... I will just take any two or more prime numbers not on your
> list and multiply them together.
>
> Rick
>
>
Yeah, I did not think it through carefully enough. I already posted a
amendment to that affect. I'm not feeling up to snuff and my mind is not
working very well.

--
Steve Kelley
Protean Instrument Corp.
```
 0
Reply skelley (70) 12/7/2005 2:19:28 PM

```Rick Rothstein [MVP - Visual Basic] wrote:
> > I believe that any number that is not prime can be divided by either
> two
> > or three. If you factor a number to the smallest factors you will (I
> > think) always have either a 2 or 3 in the list of factors unless it
> is
> > prime or the square of a prime. Someone who is more steeped in math
> will
> > correct me if I'm wrong. So If my postulate is correct then...
>
> You are incorrect. For example, 35 is not prime... it is only
> divisible by 5 and 7, so it would fail your divisible by 2 or 3 test.
> And no matter how many numbers you attempt to add to your testing, I
> can always produce a composite (non-prime) number that has different
> divisors... I will just take any two or more prime numbers not on your
> list and multiply them together.
>
> Rick

Ok, I figured out the first part, where it just has to be determined,
whether the user entered number is prime or not. I already handed in
the assignment, with the first part done, because it was due today
(Wed, Dec 7, 2005).
This is what I did for the first part:

Do while i < inputnum
if inputnum mod i = 0
then its not prime
else
i = i + 1
End If
If inputnum mod i = 0 Then
Exit For
End if
Loop

But I could not figure out how to do the second part. All I know about
the second part, is that I should use arrays (there probably are many
ways to do it, but I have to use arrays, because that is what I have
learned about). The second part is where, if a non prime number is
entered, and the program has to display all prime factors of the
number. Ex: 3 * 5 = 15.
But I feel that, I should still figure out the second part, for future
reference. It might also help me out on the exam that is coming up for
this class.

So can somebody help me with the second part?

```
 0
Reply aronb2005 (16) 12/7/2005 8:19:23 PM

```> Ok, I figured out the first part, where it just has to be determined,
> whether the user entered number is prime or not. I already handed in
> the assignment, with the first part done, because it was due today
> (Wed, Dec 7, 2005).
> This is what I did for the first part:
>
> Do while i < inputnum
>   if inputnum mod i = 0
>       then its not prime
>   else
>     i = i + 1
> End If
> If inputnum mod i = 0 Then
> Exit For
> End if
> Loop

Did you try this code out inside of VB? As used, Exit For will produce an
error. Also,

input mod i = 0

will produce a divide by zero error when i = 0 (its default value before
anything is assigned to it) the first time execution on it is attempted. You
should Dim all of the variables before you use them.

Rick

```
 0
Reply rickNOSPAMnews (2145) 12/7/2005 8:47:20 PM

```I think this does both parts.

Dim factors(0 To InputNum - 1) As Long
Dim i                          As Long
Dim n                          As Long

If InputNum Mod 2 <> 0 Then
For i = 3 to (InputNum - 1)
If InputNum Mod i = 0 Then
factors(n) = i
n = n + 1
End If
Next
End If
If n = 0 Then
'InputNum is prime
Else
'InputNum has n factors stored in factors()
End If

"new programer" <aronb2005@gmail.com> wrote:

>Ok, I figured out the first part, where it just has to be determined,
>whether the user entered number is prime or not. I already handed in
>the assignment, with the first part done, because it was due today
>(Wed, Dec 7, 2005).
>This is what I did for the first part:
>
>Do while i < inputnum
>  if inputnum mod i = 0
>      then its not prime
>  else
>    i = i + 1
>End If
>If inputnum mod i = 0 Then
>Exit For
>End if
>Loop
>
>But I could not figure out how to do the second part. All I know about
>the second part, is that I should use arrays (there probably are many
>ways to do it, but I have to use arrays, because that is what I have
>learned about). The second part is where, if a non prime number is
>entered, and the program has to display all prime factors of the
>number. Ex: 3 * 5 = 15.
>But I feel that, I should still figure out the second part, for future
>reference. It might also help me out on the exam that is coming up for
>this class.
>
>So can somebody help me with the second part?
>

```
 0
Reply nobody9919 (41) 12/7/2005 9:29:16 PM

```I don't know how that got sent twice.

Skip the If-Then around the For-Next loop. While even numbers cannot be
prime, you still need the factors.

nobody@whocares.com (Dave Houston) wrote:

>I think this does both parts.
>
>Dim factors(0 To InputNum - 1) As Long
>Dim i                          As Long
>Dim n                          As Long
>
>If InputNum Mod 2 <> 0 Then
>  For i = 3 to (InputNum - 1)
>    If InputNum Mod i = 0 Then
>      factors(n) = i
>      n = n + 1
>    End If
>  Next
>End If
>If n = 0 Then
>  'InputNum is prime
>Else
>  'InputNum has n factors stored in factors()
>End If
>
>"new programer" <aronb2005@gmail.com> wrote:
>
>>Ok, I figured out the first part, where it just has to be determined,
>>whether the user entered number is prime or not. I already handed in
>>the assignment, with the first part done, because it was due today
>>(Wed, Dec 7, 2005).
>>This is what I did for the first part:
>>
>>Do while i < inputnum
>>  if inputnum mod i = 0
>>      then its not prime
>>  else
>>    i = i + 1
>>End If
>>If inputnum mod i = 0 Then
>>Exit For
>>End if
>>Loop
>>
>>But I could not figure out how to do the second part. All I know about
>>the second part, is that I should use arrays (there probably are many
>>ways to do it, but I have to use arrays, because that is what I have
>>learned about). The second part is where, if a non prime number is
>>entered, and the program has to display all prime factors of the
>>number. Ex: 3 * 5 = 15.
>>But I feel that, I should still figure out the second part, for future
>>reference. It might also help me out on the exam that is coming up for
>>this class.
>>
>>So can somebody help me with the second part?
>>

```
 0
Reply nobody9919 (41) 12/7/2005 9:50:01 PM

```> I think this does both parts.
>
> Dim factors(0 To InputNum - 1) As Long
> Dim i                          As Long
> Dim n                          As Long
>
> If InputNum Mod 2 <> 0 Then
>   For i = 3 to (InputNum - 1)
>     If InputNum Mod i = 0 Then
>       factors(n) = i
>       n = n + 1
>     End If
>   Next
> End If
> If n = 0 Then
>   'InputNum is prime
> Else
>   'InputNum has n factors stored in factors()
> End If

When one talks of the factors of a composite (non-prime) number, they mean
the prime factors. Your code looks (I didn't try it) as if it will store the
prime numbers and all multiples of those prime numbers that divide the
original number. For example, if your number is 12, the prime factors are 2,
2 and 3. I think your code will include only one of the 2's while including
4 in there also.

By the way, you only have to run your loop to an upper bound of
Sqr(InputNum) when checking divisors of a number.

Rick

```
 0
Reply rickNOSPAMnews (2145) 12/7/2005 10:00:24 PM

```"Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net>
wrote:

>When one talks of the factors of a composite (non-prime) number, they mean
>the prime factors. Your code looks (I didn't try it) as if it will store the
>prime numbers and all multiples of those prime numbers that divide the
>original number. For example, if your number is 12, the prime factors are 2,
>2 and 3. I think your code will include only one of the 2's while including
>4 in there also.

I got into the thread late. Test the numbers in the array for primes until
there are none. I didn't try the code either - start the loop at 2.

>By the way, you only have to run your loop to an upper bound of
>Sqr(InputNum) when checking divisors of a number.

Sqr(35) < 7
5 * 7 = 35

```
 0
Reply nobody9919 (41) 12/8/2005 1:03:24 AM

```> >By the way, you only have to run your loop to an upper bound of
> >Sqr(InputNum) when checking divisors of a number.
>
> Sqr(35) < 7
> 5 * 7 = 35

But 5 is less than (or equal to) the square root of 35. I didn't say ALL
roots would be less than the square root of the number, but at least one of
them is. The loop, as posted, wouldn't work (and I point that out)... the
proper way is to test prime divisors from the lowest one up to the square
root of the number. When you find a prime root, you must divide the given
number by it and then continue the loop using the quotient from that
division. Doing it this way will catch all prime roots (provided you have a
list of primes to use).

Rick

```
 0
Reply rickNOSPAMnews (2145) 12/8/2005 1:16:45 AM

```Ok, I tried the code:
Dim factors(0 To InputNum - 1) As Long
Dim i                          As Long
Dim n                          As Long

If InputNum Mod 2 <> 0 Then
For i = 3 to (InputNum - 1)
If InputNum Mod i = 0 Then
factors(n) = i
n = n + 1
End If
Next
End If
If n = 0 Then
'InputNum is prime - here I put lblOutput.Text = "This is a prime
number"
Else
'InputNum has n factors stored in factors()  -  here i put
lblOutput.Text = "This is not a prime number"
End If

And for the line, "Dim factors(0 To InputNum - 1) As Long", VB says
that "Array declarations cannot specify lower bounds". So how do I deal
with that. Then I took the "0 To InputNum - 1" part out of the brackets
and tried running it with and without the if statements around the for
loop and the program sees every number entered as a prime number.
Also, how would you fix the problem with the code, where it will
include only one of the 2's while including 4 in there also.

```
 0
Reply aronb2005 (16) 12/8/2005 1:20:06 AM

```Rick Rothstein [MVP - Visual Basic] wrote:
> > I think this does both parts.
> >
> > Dim factors(0 To InputNum - 1) As Long
> > Dim i                          As Long
> > Dim n                          As Long
> >
> > If InputNum Mod 2 <> 0 Then
> >   For i = 3 to (InputNum - 1)
> >     If InputNum Mod i = 0 Then
> >       factors(n) = i
> >       n = n + 1
> >     End If
> >   Next
> > End If
> > If n = 0 Then
> >   'InputNum is prime
> > Else
> >   'InputNum has n factors stored in factors()
> > End If
>
> When one talks of the factors of a composite (non-prime) number, they mean
> the prime factors. Your code looks (I didn't try it) as if it will store the
> prime numbers and all multiples of those prime numbers that divide the
> original number. For example, if your number is 12, the prime factors are 2,
> 2 and 3. I think your code will include only one of the 2's while including
> 4 in there also.
>
> By the way, you only have to run your loop to an upper bound of
> Sqr(InputNum) when checking divisors of a number.
>
> Rick

How would you fix the problem where the code will include only one of
the 2's while including 4 in there also? And also how do you fix : "Dim
factors(0 To InputNum - 1) As Long", because VB says, " Array
Declarations cannot specify lower bounds".  And what do upper bounds
and/or lower bounds mean, because I have not learned about those.

```
 0
Reply aronb2005 (16) 12/8/2005 2:32:33 AM

```Rick Rothstein [MVP - Visual Basic] wrote:
> > I think this does both parts.
> >
> > Dim factors(0 To InputNum - 1) As Long
> > Dim i                          As Long
> > Dim n                          As Long
> >
> > If InputNum Mod 2 <> 0 Then
> >   For i = 3 to (InputNum - 1)
> >     If InputNum Mod i = 0 Then
> >       factors(n) = i
> >       n = n + 1
> >     End If
> >   Next
> > End If
> > If n = 0 Then
> >   'InputNum is prime
> > Else
> >   'InputNum has n factors stored in factors()
> > End If
>
> When one talks of the factors of a composite (non-prime) number, they mean
> the prime factors. Your code looks (I didn't try it) as if it will store the
> prime numbers and all multiples of those prime numbers that divide the
> original number. For example, if your number is 12, the prime factors are 2,
> 2 and 3. I think your code will include only one of the 2's while including
> 4 in there also.
>
> By the way, you only have to run your loop to an upper bound of
> Sqr(InputNum) when checking divisors of a number.
>
> Rick

How would you fix the problem where the code will include only one of
the 2's while including 4 in there also? And also how do you fix : "Dim
factors(0 To InputNum - 1) As Long", because VB says, " Array
Declarations cannot specify lower bounds".  And what do upper bounds
and/or lower bounds mean, because I have not learned about those.

```
 0
Reply aronb2005 (16) 12/8/2005 2:34:46 AM

```Adding to my last post...
1. With that line, VB says that 'factors' in the line
"factors(n) = i" is not declared. If you delete the "0 To
InputNum-1" out of the "factors(0 To InputNum - 1)", then it sees
"factors" as declared. So how do I deal with that?
2. What does upper bounds and/or lower bounds mean, because I have not

```
 0
Reply aronb2005 (16) 12/8/2005 2:43:12 AM

```Rick Rothstein [MVP - Visual Basic] wrote:
> > I think this does both parts.
> >
> > Dim factors(0 To InputNum - 1) As Long
> > Dim i                          As Long
> > Dim n                          As Long
> >
> > If InputNum Mod 2 <> 0 Then
> >   For i = 3 to (InputNum - 1)
> >     If InputNum Mod i = 0 Then
> >       factors(n) = i
> >       n = n + 1
> >     End If
> >   Next
> > End If
> > If n = 0 Then
> >   'InputNum is prime
> > Else
> >   'InputNum has n factors stored in factors()
> > End If
>
> When one talks of the factors of a composite (non-prime) number, they mean
> the prime factors. Your code looks (I didn't try it) as if it will store the
> prime numbers and all multiples of those prime numbers that divide the
> original number. For example, if your number is 12, the prime factors are 2,
> 2 and 3. I think your code will include only one of the 2's while including
> 4 in there also.
>
> By the way, you only have to run your loop to an upper bound of
> Sqr(InputNum) when checking divisors of a number.
>
> Rick

Ok, I tried the code:
Dim factors(0 To InputNum - 1) As Long
Dim i                          As Long
Dim n                          As Long

If InputNum Mod 2 <> 0 Then
For i = 3 to (InputNum - 1)
If InputNum Mod i = 0 Then
factors(n) = i
n = n + 1
End If
Next
End If
If n = 0 Then
'InputNum is prime - here I put lblOutput.Text = "This is a prime
number"
Else
'InputNum has n factors stored in factors()  -  here i put
lblOutput.Text = "This is not a prime number"
End If

And for the line, "Dim factors(0 To InputNum - 1) As Long", VB says
that "Array declarations cannot specify lower bounds". And also with
that line, VB says that 'factors' in the line "factors(n) = i"
is not declared. If you delete the "0 To InputNum-1" out of the
"factors(0 To InputNum - 1)", then it sees "factors" as
declared. So how do I deal with that. Then I took the "0 To InputNum -
1" part out of the brackets and tried running it with and without the
if statements around the for loop and the program sees every number
entered as a prime number.
Also, how would you fix the problem with the code, where it will
include only one of the 2's while including 4 in there also? And what
does upper bounds and/or lower bounds mean, because I have not learned

```
 0
Reply aronb2005 (16) 12/8/2005 2:46:37 AM

```> And for the line, "Dim factors(0 To InputNum - 1) As Long", VB says
> that "Array declarations cannot specify lower bounds".

What version of VB are you using?

Rick

```
 0
Reply rickNOSPAMnews (2145) 12/8/2005 4:35:47 AM

```I am very sorry about the fact that, the a similar message got posted
so many times. But the thing is that, when I was trying to post I kept
on getting either 'Server Error' or 'This page cannot be displayed'. So
that is why, I rewrote the message like 2 or three times. After the 2nd
time, I had remembered to save a copy of the message. But I got one or
the other error, for a total of like 5 times, and that is what I guess
led to the message being posted that many time. I checked like 20
minutes, after I submitted the message the final time, and only one had
appeared. And now when I check like, 3 or 4 hours later, the message is
there like 5 times. Again I am very sorry about that.

But getting back to the problem. First of all, I will answer the
question on what version of Visual Basic I am using and it is Visual
Basic.NET 2003.

First of all, somebody in this topic, has said that I might be working
on a take home test, which has this problem. But that is not the case.
I am not cheating. I said that a similar problem might come up on the
test., and by that I mean that I have an actual in class test, where
you can use only your head and maybe a basic calculator for arithmetic
or calculation problems. By the way, I did fine in other class
assignments (except some trouble on that other Fibonacci problem), labs
and tests, but for some reason, can't figure out the second part of
this assignment. I have already spent, at least a couple hours thinking
about the second part and maybe an hour or so, on the first part

So is it possible that somebody could post a full working code, because
I have already handed in the assignment, with the first part (it works,
see below in next paragraph) done. A similar problem might come up on
the exam and I want to study and understand the problem to prepare for
the exam. I have already spent at least a couple of hours thinking
about the second part and maybe an hour or so, on the first part, and
cannot afford to spend any more time, or have enough time before the
exam, because I got to study for this exam for programming, and I also
have exams for 3 other courses.  I also just had a major setback,
yesterday (Tues, Dec 6, 2005), when I was working on an assignment for
another class (philosophy) and my computer suddenly restarted on its
own. So now I have to redo some of that philosophy assignment and
figure out the problem with my computer and fix it. I am having a bad
week.

Somebody said, that, about the code I posted before for the first part
of the problem, that it does not work, but I just tried it and it does
work fine. You would just avoid exceptions by using Try/catch and
catching, no input, numbers less than or equal to 2, non numeric input
and numbers too large. The code I am talking about is below:

Dim inputNum As Long
inputNum = txtInput.Text
Dim i As Integer
Dim strResult As String
i = 2
Do While i < inputNum
If inputNum Mod i = 0 Then
lblOutput.Text = "This is not a prime number"

Else
i = i + 1

End If
If inputNum Mod i = 0 Then
Exit Do

End If

lblOutput.Text = "This is a prime number"
Loop

By the way, this is the message I was trying to post, in full, when I
started having the server errors and stuff:
Ok, I tried the code:
Dim factors(0 To InputNum - 1) As Long
Dim i                          As Long
Dim n                          As Long

If InputNum Mod 2 <> 0 Then
For i = 3 to (InputNum - 1)
If InputNum Mod i = 0 Then
factors(n) = i
n = n + 1
End If
Next
End If
If n = 0 Then
'InputNum is prime - here I put lblOutput.Text = "This is a prime
number"
Else
'InputNum has n factors stored in factors()  -  here i put
lblOutput.Text = "This is not a prime number"
End If

And for the line, "Dim factors(0 To InputNum - 1) As Long", VB says
that "Array declarations cannot specify lower bounds". And also with
that line, VB says that 'factors' in the line "factors(n) = i"
is not declared. If you delete the "0 To InputNum-1" out of the
"factors(0 To InputNum - 1)", then it sees "factors" as
declared. So how do I deal with that. Then I took the "0 To InputNum -
1" part out of the brackets and tried running it with and without the
if statements around the for loop and the program sees every number
entered as a prime number.
Also, how would you fix the problem with the code, where it will
include only one of the 2's while including 4 in there also? And what
does upper bounds and/or lower bounds mean, because I have not learned

```
 0
Reply aronb2005 (16) 12/8/2005 7:47:21 AM

```> But getting back to the problem. First of all, I will answer the
> question on what version of Visual Basic I am using and it is Visual
> Basic.NET 2003.

I thought so!

> Somebody said, that, about the code I posted before for the first part
> of the problem, that it does not work, but I just tried it and it does
> work fine. You would just avoid exceptions by using Try/catch and
> catching, no input, numbers less than or equal to 2, non numeric input
> and numbers too large.

For the most part, any code you receive from people in this newsgroup will
be meaningless to you.

Almost everybody in this newsgroup is using VB6 or lower. While you may get
a stray answer to VB.NET (including VB2003 and VB2005 which has dropped .NET
from its name) questions here, you should ask them in newsgroups devoted
exclusively to .NET programming (the languages are different enough to
warrant separate newsgroup support). Look for newsgroups with either the
word "dotnet" or "vsnet" in their name.

For the microsoft news server, try these newsgroups for Visual Basic .NET
related questions...

microsoft.public.dotnet.languages.vb
microsoft.public.dotnet.languages.vb.controls
microsoft.public.dotnet.languages.vb.data

And these for more general .NET questions

microsoft.public.dotnet.general
microsoft.public.vsnet.general

Note: There are many other .NET newgroups (use the first three "fields" from
the last two as templates when searching for them), but the above ones
should get you started.

Rick

```
 0
Reply rickNOSPAMnews (2145) 12/8/2005 8:00:25 AM

34 Replies
53 Views

Similar Articles

12/12/2013 8:01:16 PM
[PageSpeed]

Similar Artilces:

The Largest subscript-known prime number Prime[n]
What number is the Largest subscript-known prime number Prime[n].until now? In[1]:= Prime[10^13] During evaluation of In[1]:= Prime::largp: Argument 10000000000000 in Prime[10000000000000] is too large for this implementation. >> Out[1]= Prime[10000000000000] Prime[10^12]= 29996224275833 How powerful CPU&Mem can solve Prime[10^13] in about one day time? ...

Prime Number !!!
Hello, I need the EFFICIENT algorithm for finding whether given number is prime or not. Regards, Ajay ajay.ajaysharma@gmail.com news:1113217102.391478.223050@z14g2000cwz.googlegroups.com > I need the EFFICIENT algorithm for finding whether given number is > prime > or not. GPM math library have meany good functions in that subject. -- ~~~~=~~~~l_;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ _|\___J \____, Pozdrawiam, moje www, C++, kontakt, itd.: X-( ssn256 ) Rafal Maj Raf256 - http://www.raf256.com/me-news/ ,"-------------" (strona w bu...

Prime Numbers #2
Here is my code to generate prime numbers.It works absolutely fine when the range is *not very large*. However on initializing i with a large integer it produces erroneous results (some numbers ending in 5 ..which obviously cannot be prime numbers) can anyone please help me out with the reason?? /*Generate Prime Numbers*/ #include<stdio.h> #include<stdlib.h> struct node{ int data; struct node *next; }; node* create_node(void) { struct node *z; z=(node*)malloc(sizeof(node)); if(z==NULL) { printf("Error"); exit(0); } return z; } node* node_insert(st...

Prime Numbers #2
I am now trying to improve upon the way in which i calculate if a number is prime. I understand their a several probabilist prime checks out their, but i would like one that give a yes or no rather than a very mathematical maybe. Firstly i would like to point out that i am going to be working with numbers smaller than (2^64)-1 (AKA LONG) I have attached a rather large amount of code to this post, the code is my implementation of the Sieve of Atkin method. The first thing i would like to know... is there are fast prime checker. The second thing i would like to know is how could i impr...

Large Prime numbers
Hi Are there any efficient algorithm for generating Primes with about 50-100 decimal dight? Thanks Steve steven_82m@hotmail.com scribbled on the stall wall: > Hi > > Are there any efficient algorithm for generating Primes with about > 50-100 decimal dight? Efficient? No...reasonable approximations of a prime? yes...There are methods of testing whether a number (N) is within a certain probability of being prime. The java BigInteger class has such a method of generating a number and being (reasonably) sure it is a prime. these methods are based upon checking whether the tar...

direct calculation of prime numbers
James McCanney has published a book with a simple algorithm for iteratively computing prime numbers. Read about it at http://www.calculateprimes.com. According to McCanney, the algorithm uses only addition and subtraction and can be taught to 3rd graders. dave <daf@a64.comcast.net> writes: > James McCanney has published a book with a simple algorithm > for iteratively computing prime numbers. Read about it at > http://www.calculateprimes.com. According to McCanney, the > algorithm uses only addition and subtraction and can be taught > to 3rd graders. The same can be ...

help with a prime number algorithm
I am trying to create a function that will generate a list of the first N primes and have it use the list of primes already generated to test each new number the problem is that N in the function plist is greater than 1, it doesn't return anything I have limited experience with scheme, especial since i have taught it to myself, so I am not sure how to go about solving this ;;;returns a list of the first n primes (define plist ( lambda (n) (cond ((= n 0) '()) ((= n 1) '(2)) ((> n 1) (plist-internal n ...

Concatenation of prime factors of numbers
Can someone help me with this trick? I would like to create the following sequence, based on FactorInteger: 2,3,22,5,23,7,222,33,25,11,223,13,27,35,2222, ... where each term is the concatenation of the prime factors of n. Thanks, Diana Hello Diana, that can be done by: -FactorInteger -Convert the factor to a string and duplicate the string as many times as the exponent indicates. This produces a list -Flatten superfluous braces - Apply StringJoin to the list of strings -convert the strings to numbers using ToExpression: - the above procedure ma...

where to find all the 512 bits prime numbers?
My current project happens to need me to find all the 512 bits prime numbers.Where could I get them? Thanks very much. Fox Autumn-Fox wrote: > My current project happens to need me to find all the 512 bits prime > numbers.Where could I get them? Has someone also asked you for the stripy paint? I guess there's around 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 of them. Give or take. (Actually I can't remember the formulas for estimating the number of prim...

How can I make my prime number generator better?
How can I improve my code?... faster, better style, proper programming techniques, better algorithm? Thanks! #!/usr/bin/perl use strict; use warnings; use diagnostics; my \$n = 100000; #limit at 6 * 10^14, regex's break. my \$k = 6; #6 * 10^14, min value is 6. \$k = int((\$k / 6) + .5); my \$y1; my \$y2; for (1 .. int((\$n * .1665) + .5)) { #check 6k - 1: \$y1 = ((6 * \$k) - 1); if (\$y1 !~ m/5\$/o) { for (1 .. (int((sqrt(\$y1) * .1665) + .5))) { \$y2 = ((6 * \$_) - 1); goto end1 if ((\$y1 / \$y2) !~...

1, 2, 3, 5, 7... PRIME Numbers
1, 2, 3, 5, 7... PRIME Numbers [ Mathematics / Physics / Engineering ] ________________________________ Definitions What is a PRIME Number ? A PRIME number is a number whose only positive divisors are one and itself. What is a MAGIC SQUARE? A magic square is an arrangement of numbers in a square, such that the numbers in all rows, all columns, and both diagonals sum to the same number. ________________________________ MAGIC SQUARES & PRIME Numbers The secret of PRIME Numbers are embedded within the puzzle known as "MAGIC SQUARES". PRIME Numbers and Magic Squares go hand...

using nested for loop, workin with displaying prime numbers
Hey. Im trying to make program that basically displays all the prime numbers. I need to use bool and for but im not quite sure if i have this right. So far i have this bunch of a mess but can anyone point me in the right direction? Thanks! # include <iostream> # include <cmath> using namespace std; int i; //int sqrt; //int j; int x; int j; int limit; bool primeNumber(int); int main() { // cout << "Limit: "; // cin >> x; // if ((x % 2 == 0) & (x % x == 0)) // { // return true; // } // else // { // return false; // return 0; //} // //bool primeNumber; ...

Serial output from a 16 qubit quantum computer --- large prime numbers
Hello, www.dwavesys.com says it can construct a 1024 bit quantum computer NEXT YEAR END. But it claims it has a 16 qubit quantum computer now. *** So suppose I want to factorize a 10,000 digit prime number. The only problem is not the 16 qubits ----- but the fact that when the qubits come to rest there are only 16 bits (or 4 digits of the prime number) to be outputted. ** So we modify Shor's algorithm as follows (not me though). 1. Feed in the problem. 2. Get the prime number calculated but output only digits 1,2,3, and 4. 3. A digital computer takes in digits 1,2,3, and 4 and feeds these ...

Fibonacci Numbers and Lucas Numbers
I'm having some problems with the below equation. I have no problems when it comes to positives. Negatives create the problem.. C 2 1 4 However, this doesn't work: C -60 37 -5 Any help? I appreciate it greatly!!! #include <iostream> #include <cstdlib> #include <cmath> using namespace std; bool isFibonacciNumber (int); unsigned findFibonacciNumber (int); bool isLucasNumber (int); unsigned findLucasNumber (int); bool isInSequence (int, int, int); unsigned findInSequence (int, int, int); int main() { char choice; int n, i; int var1; int var2; cout <&...

Number of successive number in a list
I want to write a predicate to return the number of the successive numbers in a list. For example: number_of_successive_numbers([1,2,3,4,5],Number). Number = 5. or number_of_successive_number([2,5,6,7,9],Number). Number = 3. How can i do that? Thanks in advance On 16 Dec 2006 03:38:31 -0800, niarvani@csd.auth.gr wrote: >I want to write a predicate to return the number of the successive >numbers in a list. >For example: > >number_of_successive_numbers([1,2,3,4,5],Number). >Number = 5. > >or > >number_of_successive_number([2,5,6,7,9],Number). >Number = 3. ...

does a number exist in another number?
Hi guys, Hopefully an easy problem for you :) Have search around google for an hour looking for a hint on this. say I have: A=2 and B=123 Is there a way to see if A exists in B at all? Cheers On 4/27/2011 10:04 PM, Nick Patterson wrote: > Hi guys, > > Hopefully an easy problem for you :) > > Have search around google for an hour looking for a hint on this. > > say I have: > > A=2 and B=123 > > Is there a way to see if A exists in B at all? > > Cheers Not sure what you mean by "A exists in B at all?" You mean as a digit? if so, then may ...

sort number with deleting the same number
Hi all... How can I sort the number and delete the the number which has the same number for ex: a= 3 5 2 4 3 4 4 into a=2 3 4 5 thanks alot P� Wed, 16 Feb 2005 01:19:45 -0500, skrev wahyu <addy_w33@yahoo.com>: > Hi all... > > How can I sort the number and delete the the number which has the > same number > > for ex: > a= 3 5 2 4 3 4 4 > > into > a=2 3 4 5 > > thanks alot help unique -- K Hi, a=[3 5 2 4 3 4 4]; a=sort(unique(a)) J�r�me J�r�me wrote: > > > Hi, > > a=[3 5 2 4 3 4 4]; > a=sort(unique(a)) > > J�r�me >...

getting the left 2 numbers of a number
if x=1234567 how can I get the first two left digits i.e 12 using matlab?. in excel it is easy : left(x,2) but I couldn't find a left function in matlab "joseph Frank" <josephfrank1969@hotmail.com> wrote in message <h575n6\$7vg\$1@fred.mathworks.com>... > if x=1234567 > how can I get the first two left digits i.e 12 using matlab?. in excel it is easy : left(x,2) but I couldn't find a left function in matlab one of the solutions x=1234567; % <- a DOUBLE s=sprintf('%d',x); s=s(1:2) % s = 12 % <- a CHAR string us "...

single random number (not a vector of numbers)
I'm fairly new to Simulink. I read a previous thread on how to produce a random number and it was helpful. However, I need to produce a single random number and not a series of random numbers. I would like for only 1 random number to be passed through to my function each time I run a simulation. I'm using Constant(1)-->function rand()-->scope. ...

Finding all numbers which add up to another number
Hi everyone, I'm looking for a way to pass a number into a subroutine, and have it give back a list of all the ways that number can been added to get to that number. For example, if the function were to take 3 as a parameter it would give me back: 1,1,1 2,1 3 for 5 it would give back: 1,1,1,1,1 2,2,1 3,2 3,1,1 4,1 5 2,1,1,1 I haven't been able to come up with anything that does this the way I want: So far I did: &Sum(3) sub Sum { my \$sum = shift; for (my \$i=0; \$i<=\$sum; \$i++) { for (my \$j=0; \$j<=\$sum; \$j++) { for (my \$k=0; \$k<=\$sum; \$k++) { ...