comp.lang.ada
 help / color / mirror / Atom feed
* Prime number program?
@ 1999-12-04  0:00 Oly
  1999-12-04  0:00 ` Robert L. Klungle
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Oly @ 1999-12-04  0:00 UTC (permalink / raw)


Please help!

I have to build an Ada program which tells the user if the number which they
have entered is a prime number or not.
I am still a newbie at Ada (and crap at maths)..and have spent many wasted
and frustring hours trying to solve the problem.

Please help!


(o_fox@hotmail.com);






^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Prime number program?
  1999-12-04  0:00 Prime number program? Oly
@ 1999-12-04  0:00 ` Robert L. Klungle
  1999-12-04  0:00 ` Larry Kilgallen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Robert L. Klungle @ 1999-12-04  0:00 UTC (permalink / raw)


Oly wrote:

> Please help!
>
> I have to build an Ada program which tells the user if the number which they
> have entered is a prime number or not.
> I am still a newbie at Ada (and crap at maths)..and have spent many wasted
> and frustring hours trying to solve the problem.
>
> Please help!
>
> (o_fox@hotmail.com);

Hint:  a prime number is any positive integer which is only divisible,
with no remainder, by one (1) and itself.





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Prime number program?
  1999-12-04  0:00 Prime number program? Oly
  1999-12-04  0:00 ` Robert L. Klungle
@ 1999-12-04  0:00 ` Larry Kilgallen
  1999-12-04  0:00 ` E. Robert Tisdale
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Larry Kilgallen @ 1999-12-04  0:00 UTC (permalink / raw)


In article <82bk0d$55b$1@saturn.bton.ac.uk>, "Oly" <o.fox@bton.ac.uk> writes:
> Please help!
> 
> I have to build an Ada program which tells the user if the number which they
> have entered is a prime number or not.
> I am still a newbie at Ada (and crap at maths)..and have spent many wasted
> and frustring hours trying to solve the problem.
> 
> Please help!

If you don't know the math regarding prime numbers, you cannot
succeed on such an endeavor no matter what programming language
you use.

Thus, I think this is not really an Ada question, and something
more appropriate to some math discussion forum.

When you resolve your math question, any introductory Ada book
should show you how basics like addition, subtraction, etc. work.

Larry Kilgallen




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Prime number program?
  1999-12-04  0:00 Prime number program? Oly
  1999-12-04  0:00 ` Robert L. Klungle
  1999-12-04  0:00 ` Larry Kilgallen
@ 1999-12-04  0:00 ` E. Robert Tisdale
  1999-12-06  0:00 ` skamn
  1999-12-13  0:00 ` Robert I. Eachus
  4 siblings, 0 replies; 6+ messages in thread
From: E. Robert Tisdale @ 1999-12-04  0:00 UTC (permalink / raw)


Oly wrote:

> I have to build an Ada program which tells the user
> if the number which they have entered is a prime number or not.
> I am still a newbie at Ada (and crap at maths)
> and have spent many wasted and frustrating hours
> trying to solve the problem.

I used Lycos to search for +prime +number +algorithm
and I found lots of stuff including

    http://www.utm.edu/research/primes/

It is very hard to determine whether or not a number n is prime
and that is one of the reasons why prime number figure
very prominently in encryption algorithms.
Suppose that the square root of n is not an integer.
Then you will need to test whether n/p is an integer
for every prime number p < sqrt(n)
which means that you need a list
of all the prime numbers p < sqrt(n).
Programs which find all the prime numbers
in a range of integers are called prime number sieves.
The one on my computer is called "primes."

    $ primes 0 10
    2
    3
    5
    7
    $

Hope this helps, E. Robert Tisdale <edwin@netwood.net>





^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Prime number program?
  1999-12-04  0:00 Prime number program? Oly
                   ` (2 preceding siblings ...)
  1999-12-04  0:00 ` E. Robert Tisdale
@ 1999-12-06  0:00 ` skamn
  1999-12-13  0:00 ` Robert I. Eachus
  4 siblings, 0 replies; 6+ messages in thread
From: skamn @ 1999-12-06  0:00 UTC (permalink / raw)


In article <82bk0d$55b$1@saturn.bton.ac.uk>,
  "Oly" <o.fox@bton.ac.uk> wrote:
> Please help!
>
> I have to build an Ada program which tells the
user if the number which they
> have entered is a prime number or not.
> I am still a newbie at Ada (and crap at
maths)..and have spent many wasted
> and frustring hours trying to solve the problem.
>
> Please help!
>
> (o_fox@hotmail.com);
>
>
Here is a simple procedure in C that returns if
a number is prime. I had a similar Ada program
but I can't find it. Hope this helps.
/* return if a number is prime or not */
int IsPrime( int y) {
        int rema;
        int counter = 0;
        int n;
        for (n =1; n <= y; n++) {
                rema = y%n;
                if (rema == 0)
                        counter = counter + 1;
        }
                if (counter <= 2)
                        return 0;
                else
                        return 1;




Sent via Deja.com http://www.deja.com/
Before you buy.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Prime number program?
  1999-12-04  0:00 Prime number program? Oly
                   ` (3 preceding siblings ...)
  1999-12-06  0:00 ` skamn
@ 1999-12-13  0:00 ` Robert I. Eachus
  4 siblings, 0 replies; 6+ messages in thread
From: Robert I. Eachus @ 1999-12-13  0:00 UTC (permalink / raw)



Oly wrote:
  
> I have to build an Ada program which tells the user if the number which they
> have entered is a prime number or not.
> I am still a newbie at Ada (and crap at maths)..and have spent many wasted
> and frustring hours trying to solve the problem.

  I have always liked this method for testing primality.  But I suggest
you study both Ada and Number Theory before handing this example in as
your own work...

with Ada.Text_IO, Ada.Integer_Text_IO;
procedure Prime is
-- a program using Wilson's Theorem to test for primality.  May fail for
-- numbers greater than 2**(Natural'Size/2).
-- Enter zero or a negative value to exit.
  P: Integer;
  Temp: Integer;
  use Ada.Text_IO, Ada.Integer_Text_IO;
begin
  loop
    Put_Line("Enter candidate:");
    Get(P);
    Skip_Line;
    exit when P <= 0;
    Temp := 1;
    for I in 2..P-1 loop
      Temp := (Temp*I) mod P;
    end loop;
    if Temp = P-1
    then Put(P,12); Put_Line(" is prime.");
    else Put(P,12); Put_Line(" is not a prime.");
    end if;
  end loop;
  Put_Line("  All done.");
exception
  when others => Put_Line("  Ooops!");
end Prime;

-- 

                                        Robert I. Eachus

with Standard_Disclaimer;
use  Standard_Disclaimer;
function Message (Text: in Clever_Ideas) return Better_Ideas is...




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1999-12-13  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-12-04  0:00 Prime number program? Oly
1999-12-04  0:00 ` Robert L. Klungle
1999-12-04  0:00 ` Larry Kilgallen
1999-12-04  0:00 ` E. Robert Tisdale
1999-12-06  0:00 ` skamn
1999-12-13  0:00 ` Robert I. Eachus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox