Palindromic numbers

i have to write an application to find the smallest palindromic numbers made from the product of three 3-digit positive integers that have even and odd numbers of digits? how would i do this?

I used this code as a template but i dont understand how to modify it:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>

using std::cout;
using std::endl;


int main()
{   
	//declare variables
	int i, j, z;   
	int num;    
	char buf[7];
	char test[7];
	
	for(i=100; i<=999; i = i +1) 
	{         
		for(j=100; j<=999; j = j +1)      
		{          
			num = i * j;    

			sprintf(buf, "%d", num);          
			
			for(z=0; z<=6; z++)    
				test[z]=buf[z]; 
               
			int len=strlen(buf);      
			
			for(z=0; z<len/2;z++)          
			{               
				test[z]^=test[len-z-1];
				test[len-z-1]^=test[z];
				test[z]^=test[len-z-1]; 
			}    
			/*puts(buf);*/   
			/*puts(test);*/     
			/*printf("\n");*/        
			if(test == buf)               
				puts(buf); 
				cout << z;
		}     
		
	}       return 0; 
}	//end of main function 
This code shouldn't work. test == buf will never be true as they are constant pointers to different arrays. xor (^=) thing is not needed at all either. All you want to do is check that buf[z] ==buf[len-z-1] for all z from 0 to len/2.
Anyway, what you need to do is write a function bool is_palindrome(int i); and then put it in three nested "for i = 100 to 999" loops.
Topic archived. No new replies allowed.