15,791,806 members
1.00/5 (1 vote)
See more:
The Homogeneous number is a number if we invert its digits it stay the same number e.g: 123454321, 5665, 33, 1 . All these numbers are Homogeneous.
Please i need non recursive solution that accepts user input.
Posted
Sergey Alexandrovich Kryukov 24-Mar-12 18:22pm
Who told you this name? If contradicts the definition. This is called palindrome. If you think a bit, you will see that, first, "number" is irrelevant, second, this is not about number but about strings. The numbers 3113 = 003113, but fist is palindrome and second is not. This is all about strings.

Now, what did you try and how it could be a problem at all? If this is because you are a beginner, its even more important that you solve this simple problem by yourself. Also, try to solve it using no intermediate container. If you need one, the solution is very bad.

--SA

## Solution 2

Homogeneous numbers are not as you describe - two numbers are homogeneous if they have identical prime factors. An example of a homogeneous pair is (6, 72), both of which share prime factors 2 and 3.

Your numbers are palindromes. If you want to work out true homogenoeous numbers, then start with wiki and move to algorithms via Google - but be aware this gets complex, since efficient factorization is the root of most cryptography.

To process palindromic numbers is pretty simple - a non recursive technique is better than a recursive one, it is much easier to work out.

However, since this is your homework, I won't give you any code!

1) Write a method returning a bool, call it `IsPalindrome` - the method should have a single string parameter
2) Declare an integer, called `last`, set it to the length of the string, minus one - this is the last character in the string.
3) Set up a loop. A `for` loop is good, start at zero, end at the string length divided by two, increment by one.
4) In the loop, compare the current character (as given by the loop index) with it's matching character (as given by the last character minus the loop index)
5) If there are different, the string is not a palindrome, so return false immediately.
6) At the end of the loop, the string is a palindrome, so return true.

Done!