I am working on an assignment to get an intiger from user, find all prime numbers smaller that it, and show all of them which dont contain a '1'. for breaking the integer into digits, I am using " x / 10 % 10 " algorythem, but I as it becomes a double , I cant use % with the double. and I dont know how to cast the double to integer before calculating %. thx for your help.

Recommended Answers

All 3 Replies

int iNum;
double dNum = 3.61;
iNum = (int) dNum;

I am working on an assignment to get an intiger from user, find all prime numbers smaller that it, and show all of them which dont contain a '1'. for breaking the integer into digits, I am using " x / 10 % 10 " algorythem, but I as it becomes a double , I cant use % with the double. and I dont know how to cast the double to integer before calculating %. thx for your help.

So you are dealing with integers, and prime numbers are by definition integers, why are you using doubles? There should be no doubles in you program. So don't use floating point at all. Just use ints and the % works fine.

I as it becomes a double , I cant use % with the double. and

Just to let you know there is a function there is a function [search]fmod(double x,double y)[/search] which exactly does the same thing.

But as Mr. WaltP has already pointed out, dont use double if your aim is to find out prime numbers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.