[Tutor] checking if a variable is an integer?

Alan Gauld alan.gauld at btinternet.com
Wed Jun 1 00:48:11 CEST 2011


"Hans Barkei" <handihans at gmail.com> wrote

>I want to make  a program that finds all the prime numbers up to a 
>number
> inputed by the user.
> I want to know if it is an integer because that will tell me if it 
> is
> divisible by that number or not.

I assume you meant the result of the division?
If so it is better to use the modulo operator as
Hugo suggested.

There are several algorithms for this, search the internet
(wikipedia under primes is a good start). Otherwise you
will write a lot of unnecessary code and perform even
more unnecessary calculations....


-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/




More information about the Tutor mailing list