Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- bool is_pal(char * str);
- void reverse(char *x, int begin, int end);
- void reverse(char *x);
- int _tmain(int argc, _TCHAR* argv[]){
- char numc[10];
- sprintf(numc,"%d",123456);
- int a=999,b=999,numi = 0, found = 0;
- while (b > 99){
- for (int i = a; i >= b; --i ){
- numi = b * i;
- sprintf(numc, "%d", numi);
- if (is_pal(numc) == 0){
- if(numi > found){
- found = numi;
- }
- //printf("found!\n");
- }
- }
- --b;
- }
- printf("palindrome is '%d'\n", found);
- return 0;
- }
- bool is_pal(char * str){
- size_t len = strlen(str);
- char * rev;
- rev = new char[len+1];
- strcpy(rev, str);
- reverse(rev);
- bool it_is = strcmp(str,rev);
- delete [] rev;
- return it_is;
- }
- void reverse(char *x){
- reverse(x, 0, strlen(x)-1);
- }
- void reverse(char *x, int begin, int end){
- char c;
- if (begin >= end)
- return;
- c = *(x+begin);
- *(x+begin) = *(x+end);
- *(x+end) = c;
- reverse(x, ++begin, --end);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement