Pasca program
Author Message
Pasca program

Hi everyone, I need to build a Pascal program that will give me all the
factors of a whole number, ie, 8, would be 1,2,4,8. if I tyoe in 11, the
program has to give me 1,11. can anyone help me develop a small program?

thanks,

Sat, 15 Mar 2003 03:00:00 GMT
Pasca program
You just saved my life, I should have been reading a bit more about that MOD
function, thanks a million.

Martin Rowley.

Quote:
> On Tue, 26 Sep 2000 20:32:08 -0400, Martin Rowley posted:
> >Hi everyone, I need to build a pascal program that will give me all the
> >factors of a whole number, ie, 8, would be 1,2,4,8. if I tyoe in 11, the
> >program has to give me 1,11. can anyone help me develop a small program?

> >thanks,

> Sounds like a homework assignment.

> What I'd do is loop i from 1 to x.  At each stage test
>  if x mod i = 0 then number is evenly divisible

> --

Sat, 15 Mar 2003 03:00:00 GMT
Pasca program
On Tue, 26 Sep 2000 20:32:08 -0400, Martin Rowley posted:

Quote:
>Hi everyone, I need to build a pascal program that will give me all the
>factors of a whole number, ie, 8, would be 1,2,4,8. if I tyoe in 11, the
>program has to give me 1,11. can anyone help me develop a small program?

>thanks,

Sounds like a homework assignment.

What I'd do is loop i from 1 to x.  At each stage test
if x mod i = 0 then number is evenly divisible

--

Sun, 16 Mar 2003 10:07:18 GMT
Pasca program
you can also use the AND statement for figuring out when a value is odd or
even.. And I suggest you try this method. Since it is the only method in
Assembly to figure this one out.

if you have a integer (which is 16 bits) the LSB (Least Significant Bit)
always tell when a value is odd (1) or even (0).

(note this works only on bytes/integers/longintegers, not on single, real,
double, etc)

if (MyValue and \$01) then WriteLn ('Value is Odd') else WriteLn ('Value is
Even');

Peter Santing Out!

Quote:
> You just saved my life, I should have been reading a bit more about that
MOD
> function, thanks a million.

> Martin Rowley.

> > On Tue, 26 Sep 2000 20:32:08 -0400, Martin Rowley posted:
> > >Hi everyone, I need to build a pascal program that will give me all the
> > >factors of a whole number, ie, 8, would be 1,2,4,8. if I tyoe in 11,
the
> > >program has to give me 1,11. can anyone help me develop a small
program?

> > >thanks,

> > Sounds like a homework assignment.

> > What I'd do is loop i from 1 to x.  At each stage test
> >  if x mod i = 0 then number is evenly divisible

> > --

Sun, 16 Mar 2003 03:00:00 GMT
Pasca program

Quote:
>you can also use the AND statement for figuring out when a value is odd or
>even.. And I suggest you try this method. Since it is the only method in
>Assembly to figure this one out.

That is not true. You can rotate the lsb (RCR?) into the carry, and test the
carry. :-)

Quote:
>(note this works only on bytes/integers/longintegers, not on single, real,
>double, etc)

Floating point values never are exactly integer, so odd/even is not
possible.

Sun, 16 Mar 2003 03:00:00 GMT
Pasca program

Quote:
> >you can also use the AND statement for figuring out when a value is odd
or
> >even.. And I suggest you try this method. Since it is the only method in
> >Assembly to figure this one out.

> That is not true. You can rotate the lsb (RCR?) into the carry, and test
the
> carry. :-)

heheh, you like to nitpick do you??

although I don't think it matters when speed is a concern..

mov    ax, [CD00h]            ; just
load a integer/word value into AX from CD00h
and    ax, 01h                     ;
test LSB
jz    even
odd:                                ; code for odd
jmp next
even:                                ; code for even
next:

mov    ax, [CD00h]
rcr       ax
jnc       even
odd:                                ; code of odd
jmp next
even:                              ; code for even
next:

although there may be some difference in the number of states which is
required to calculate such thing.

Sun, 16 Mar 2003 03:00:00 GMT
Pasca program
Another fast algorithm determines the prime dividers and then creates all
dividers by combining them by multiplication.

Quote:
> Hi everyone, I need to build a pascal program that will give me all the
> factors of a whole number, ie, 8, would be 1,2,4,8. if I tyoe in 11, the
> program has to give me 1,11. can anyone help me develop a small program?

> thanks,

Sun, 16 Mar 2003 03:00:00 GMT
Pasca program

Quote:

>Hi everyone, I need to build a pascal program that will give me all the
>factors of a whole number, ie, 8, would be 1,2,4,8. if I tyoe in 11, the
>program has to give me 1,11. can anyone help me develop a small program?

When is it due?

Jud McCranie

Sun, 16 Mar 2003 03:00:00 GMT
Pasca program

Quote:
>Floating point values never are exactly integer, so odd/even is not
>possible.

They can be exactly an integer, and they will remain that way as
long as you don't exceed the range it can represent exactly, or
divide by an integer that doesn't divide evenly, or divide by
something that isn't an integer.
Jud McCranie

Sun, 16 Mar 2003 03:00:00 GMT
Pasca program
On Wed, 27 Sep 2000 02:07:18 GMT, Tim Dixon sez:

Quote:
>What I'd do is loop i from 1 to x.  At each stage test
> if x mod i = 0 then number is evenly divisible

That's very clever!  All my life - and I've been coding
in 5 or 6 different languages over the last 20 years - I
have done if (i/2) = int(i/2) just because that's the
way I was taught from the start and never thought
of doing it any differently.

Of course, the modulus operator wasn't available
in Honeywell CP-6 COBOL so we had to make
do with what we had :-)  Well, you're never too
old to learn a new hack, eh?

Uhm... don't you mean i mod 2?  x mod i produces
some pretty bizarre results.

Peter B. Steiger
Cheyenne, WY
----
If you reply by email, send it to pbs at com dot

Sun, 16 Mar 2003 03:00:00 GMT
Pasca program
On Wed, 27 Sep 2000 21:39:19 GMT, Peter B. Steiger posted:

Quote:
>On Wed, 27 Sep 2000 02:07:18 GMT, Tim Dixon sez:
>>What I'd do is loop i from 1 to x.  At each stage test
>> if x mod i = 0 then number is evenly divisible

>That's very clever!  All my life - and I've been coding
>in 5 or 6 different languages over the last 20 years - I
>have done if (i/2) = int(i/2) just because that's the
>way I was taught from the start and never thought
>of doing it any differently.

>Of course, the modulus operator wasn't available
>in Honeywell CP-6 COBOL so we had to make
>do with what we had :-)  Well, you're never too
>old to learn a new hack, eh?

>Uhm... don't you mean i mod 2?  x mod i produces
>some pretty bizarre results.

Yeah, saves a divide. :) Although being a COBOL guy you'd have probably
written something like
IF THE REMAINDER OF THE_NUMBER_IM_LOOPING_THROUGH DIVIDED BY ...
nah.  I'll be nice. :)

I was using i as s loop index.  He needed to check each value from 1 up to
the number.  Probably should have made that clearer.  Darn fortranism! (and
I've never really programmed in Fortran! <grin>)

--

Mon, 17 Mar 2003 10:08:18 GMT

 Page 1 of 1 [ 13 post ]

Relevant Pages