Hi, I was wondering what's wrong with my code, it seems logically correct if you follow through them.. My code is supposed to find palindromic numbers which are numbers that can be read backwards and forward and it will still be the same. For example, 1234321. Help would be greatly appreciated.
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
int x = 100;
int y = 100;
int product;
while ( (1000 > x > 100) && (1000 > y > 100))
{
product = x*y;
if ( product > 100000)
{
int a[6];
int n = 0; //exponent, for example 10^n
int m; //digit of number
while (n < 6)
{
m = product / (10^n);
for ( int b=0; b < 6; b++)
{
a[b] = m;
}
if (product < 100000)
{
int a[5];
int n = 0; //exponent, for example 10^n
int m; //digit of number
while (n < 6)
{
m = product / (10^n);
for ( int b=0; b < 6; b++)
{
a[b] = m;
}
}
if (a[0] == a[4] && a[1] == a[3])
cout << a[0] << a[1] << a[2] << a[3] << a[4] << " is a palindromic number." << endl;
This was my first ever post on cplusplus forum and it is a palindrome number checker. The parameters take the number you are trying to determine if it is palindrome and it takes the length of the number(log10(number)) and it returns true if the number is palindrome and false if not. Of course now that I look at it, there are many optimizations that can be made to it. But it runs pretty fast because it is able to find the 1 billionth palindrome value starting from 1 in about .03 ms. This was of course due to some optimizations used in the main code.
Hint in terms of optimization:
numbers divisible by 10 are not palindrome. There is no such thing as 010 in base 10 numbers
Yes, thank you, but here's the thing, someone could just post their code and have me just copy and paste it. I want to know what's wrong with my code. It seems that's what you guys are somewhat doing, putting the numbers in an array and comparing the values. Which is the same approach I tried. But nothing shows up. It's just a blank commant prompt.
sorry, the function doesn't work. POW should be operated on float or double, not with integers.
I now have a question: how do we raise 10 to a certain power and keep it as an integer??
what do you mean by that? what i'm trying to do is set up an array of x elements so that each number of the product fits into a spot in the array. or does that not work?
i actually took a break from coding due to midterms and the fact that i am too far behind with school. i am finally done with finals. so i was wondering what's wrong with my method? am i over complicating things?