0

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.

4
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by ~s.o.s~
0

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.