Re: [Dev-C++] trying to write a program which determines an integer as palindrome or not
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Per W. <pw...@ia...> - 2004-06-21 20:41:12
|
pow() isn't a very good function to use, since it is using floating point. Floating point and integer arithmetic should be kept apart unless there is really a very strong reason for mixing them. Note also that pow() is a bit expensive function. I would assume that the question here is to sift through large number of primes to locate palindromes. For a lot of programming experience with palindromes and other similar things, see: http://www.mathschallenge.net/index.php?section=project /Per W On Mon, 21 Jun 2004, David McKen wrote: > short get_digit(int number, short place) > { > return (number / pow(10,place)) % 10; > } > > The above code can get you the digit at position x. I think you can > figure it out from there. > > If you want all the digits one time you could use an array > //assume the number you want to test is in an int variable called num. > int digits[5]; > for(int i = 0; i < 5; i++) > { > digits[i] = num % 10; > num = num / 10; > } > > The rest is simple. > > Is this homework? > > dirty dragon wrote: > > > hi everyone, > > trying to write a program which determines a 5 digit integer to be a > > palindrome or not. > > i'd like to use mudulus and division operands to separate parts of a 5 > > digit integer. > > any suggestions? > > > > i posted this on the dev-users forum yesterday but i can't get into > > the forums today. anyone else having trouble? > > > > thanx pete > > > > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & Training. > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - > digital self defense, top technical experts, no vendor pitches, > unmatched networking opportunities. Visit www.blackhat.com > _______________________________________________ > Dev-cpp-users mailing list > Dev...@li... > TO UNSUBSCRIBE: http://www23.brinkster.com/noicys/devcpp/ub.htm > https://lists.sourceforge.net/lists/listinfo/dev-cpp-users > |