Computer Science Canada

Primary Divisors Help

Author:  compstudent [ Thu Feb 24, 2011 6:53 pm ]
Post subject:  Primary Divisors Help

Hi
I am making a simple program that finds all the prime divisors of a given number.

Turing:



var test:int
var divs : int
put "Please enter a number"
get test

function prime (a : int) : boolean
    for i : 2 .. a
        if a mod i = 0 then
            result false
        end if
    end for
    result true
end prime

procedure find (test : int)
    for x : 2 .. test
        if test mod x = 0 then
           divs:= test/x
        end if
    end for
    if prime(divs) = true then
    put divs, " Is a prime divisor of ", test
    end if
end find


The problem I am having is with the divs = test/x. It says it is the wrong type but if I change it to a real then it doesn`t work in the prime function in the for loop.

Thanks

Author:  Tony [ Thu Feb 24, 2011 7:29 pm ]
Post subject:  RE:Primary Divisors Help

Was there supposed to be a question in here?

Author:  compstudent [ Thu Feb 24, 2011 7:30 pm ]
Post subject:  Re: Primary Divisors Help

Is there any way to change and Int to a real or vise versa, or any other solution to my problem?

sorry.

Author:  Tony [ Thu Feb 24, 2011 7:47 pm ]
Post subject:  RE:Primary Divisors Help

you are probably looking for div operator.


: