[ create a new paste ] login | about

Link: http://codepad.org/UsPY7eW5    [ raw code | output | fork ]

C++, pasted on Sep 26:
#include <cmath>
#include <iostream>

bool is_palindrome( int X )
{
    int Temp1, Temp2, L = (int)pow( 10.0, (double)(int)log10( (double)X ) );
    while ( L )
    {
        Temp1 = X % 10;
        Temp2 = X / L;
        if ( Temp1 != Temp2 )
            return false;
        X %= L;
        X /= 10;
        L /= 100;
    }
    return true;
}

int main()
{
    int N;

    N = 2550;
    
    for ( int i = 1; i <= N; ++i )
    {
        if ( is_palindrome( i ) )
        {
            std::cout << i << " is palindrome";
            if ( is_palindrome( i * i ) )
                std::cout << " & square of " << i << " ( " << i * i << " ) palindrome too" << std::endl;
            else
                std::cout << ", but square of " << i << " ( " << i * i << " )isn't palindrome" << std::endl;
        }
    }

    return 0;
}


Output:
1 is palindrome & square of 1 ( 1 ) palindrome too
2 is palindrome & square of 2 ( 4 ) palindrome too
3 is palindrome & square of 3 ( 9 ) palindrome too
4 is palindrome, but square of 4 ( 16 )isn't palindrome
5 is palindrome, but square of 5 ( 25 )isn't palindrome
6 is palindrome, but square of 6 ( 36 )isn't palindrome
7 is palindrome, but square of 7 ( 49 )isn't palindrome
8 is palindrome, but square of 8 ( 64 )isn't palindrome
9 is palindrome, but square of 9 ( 81 )isn't palindrome
11 is palindrome & square of 11 ( 121 ) palindrome too
22 is palindrome & square of 22 ( 484 ) palindrome too
33 is palindrome, but square of 33 ( 1089 )isn't palindrome
44 is palindrome, but square of 44 ( 1936 )isn't palindrome
55 is palindrome, but square of 55 ( 3025 )isn't palindrome
66 is palindrome, but square of 66 ( 4356 )isn't palindrome
77 is palindrome, but square of 77 ( 5929 )isn't palindrome
88 is palindrome, but square of 88 ( 7744 )isn't palindrome
99 is palindrome, but square of 99 ( 9801 )isn't palindrome
101 is palindrome & square of 101 ( 10201 ) palindrome too
111 is palindrome & square of 111 ( 12321 ) palindrome too
121 is palindrome & square of 121 ( 14641 ) palindrome too
131 is palindrome, but square of 131 ( 17161 )isn't palindrome
141 is palindrome, but square of 141 ( 19881 )isn't palindrome
151 is palindrome, but square of 151 ( 22801 )isn't palindrome
161 is palindrome, but square of 161 ( 25921 )isn't palindrome
171 is palindrome, but square of 171 ( 29241 )isn't palindrome
181 is palindrome, but square of 181 ( 32761 )isn't palindrome
191 is palindrome, but square of 191 ( 36481 )isn't palindrome
202 is palindrome & square of 202 ( 40804 ) palindrome too
212 is palindrome & square of 212 ( 44944 ) palindrome too
222 is palindrome, but square of 222 ( 49284 )isn't palindrome
232 is palindrome, but square of 232 ( 53824 )isn't palindrome
242 is palindrome, but square of 242 ( 58564 )isn't palindrome
252 is palindrome, but square of 252 ( 63504 )isn't palindrome
262 is palindrome, but square of 262 ( 68644 )isn't palindrome
272 is palindrome, but square of 272 ( 73984 )isn't palindrome
282 is palindrome, but square of 282 ( 79524 )isn't palindrome
292 is palindrome, but square of 292 ( 85264 )isn't palindrome
303 is palindrome, but square of 303 ( 91809 )isn't palindrome
313 is palindrome, but square of 313 ( 97969 )isn't palindrome
323 is palindrome, but square of 323 ( 104329 )isn't palindrome
333 is palindrome, but square of 333 ( 110889 )isn't palindrome
343 is palindrome, but square of 343 ( 117649 )isn't palindrome
353 is palindrome, but square of 353 ( 124609 )isn't palindrome
363 is palindrome, but square of 363 ( 131769 )isn't palindrome
373 is palindrome, but square of 373 ( 139129 )isn't palindrome
383 is palindrome, but square of 383 ( 146689 )isn't palindrome
393 is palindrome, but square of 393 ( 154449 )isn't palindrome
404 is palindrome, but square of 404 ( 163216 )isn't palindrome
414 is palindrome, but square of 414 ( 171396 )isn't palindrome
424 is palindrome, but square of 424 ( 179776 )isn't palindrome
434 is palindrome, but square of 434 ( 188356 )isn't palindrome
444 is palindrome, but square of 444 ( 197136 )isn't palindrome
454 is palindrome, but square of 454 ( 206116 )isn't palindrome
464 is palindrome, but square of 464 ( 215296 )isn't palindrome
474 is palindrome, but square of 474 ( 224676 )isn't palindrome
484 is palindrome, but square of 484 ( 234256 )isn't palindrome
494 is palindrome, but square of 494 ( 244036 )isn't palindrome
505 is palindrome, but square of 505 ( 255025 )isn't palindrome
515 is palindrome, but square of 515 ( 265225 )isn't palindrome
525 is palindrome, but square of 525 ( 275625 )isn't palindrome
535 is palindrome, but square of 535 ( 286225 )isn't palindrome
545 is palindrome, but square of 545 ( 297025 )isn't palindrome
555 is palindrome, but square of 555 ( 308025 )isn't palindrome
565 is palindrome, but square of 565 ( 319225 )isn't palindrome
575 is palindrome, but square of 575 ( 330625 )isn't palindrome
585 is palindrome, but square of 585 ( 342225 )isn't palindrome
595 is palindrome, but square of 595 ( 354025 )isn't palindrome
606 is palindrome, but square of 606 ( 367236 )isn't palindrome
616 is palindrome, but square of 616 ( 379456 )isn't palindrome
626 is palindrome, but square of 626 ( 391876 )isn't palindrome
636 is palindrome, but square of 636 ( 404496 )isn't palindrome
646 is palindrome, but square of 646 ( 417316 )isn't palindrome
656 is palindrome, but square of 656 ( 430336 )isn't palindrome
666 is palindrome, but square of 666 ( 443556 )isn't palindrome
676 is palindrome, but square of 676 ( 456976 )isn't palindrome
686 is palindrome, but square of 686 ( 470596 )isn't palindrome
696 is palindrome, but square of 696 ( 484416 )isn't palindrome
707 is palindrome, but square of 707 ( 499849 )isn't palindrome
717 is palindrome, but square of 717 ( 514089 )isn't palindrome
727 is palindrome, but square of 727 ( 528529 )isn't palindrome
737 is palindrome, but square of 737 ( 543169 )isn't palindrome
747 is palindrome, but square of 747 ( 558009 )isn't palindrome
757 is palindrome, but square of 757 ( 573049 )isn't palindrome
767 is palindrome, but square of 767 ( 588289 )isn't palindrome
777 is palindrome, but square of 777 ( 603729 )isn't palindrome
787 is palindrome, but square of 787 ( 619369 )isn't palindrome
797 is palindrome, but square of 797 ( 635209 )isn't palindrome
808 is palindrome, but square of 808 ( 652864 )isn't palindrome
818 is palindrome, but square of 818 ( 669124 )isn't palindrome
828 is palindrome, but square of 828 ( 685584 )isn't palindrome
838 is palindrome, but square of 838 ( 702244 )isn't palindrome
848 is palindrome, but square of 848 ( 719104 )isn't palindrome
858 is palindrome, but square of 858 ( 736164 )isn't palindrome
868 is palindrome, but square of 868 ( 753424 )isn't palindrome
878 is palindrome, but square of 878 ( 770884 )isn't palindrome
888 is palindrome, but square of 888 ( 788544 )isn't palindrome
898 is palindrome, but square of 898 ( 806404 )isn't palindrome
909 is palindrome, but square of 909 ( 826281 )isn't palindrome
919 is palindrome, but square of 919 ( 844561 )isn't palindrome
929 is palindrome, but square of 929 ( 863041 )isn't palindrome
939 is palindrome, but square of 939 ( 881721 )isn't palindrome
949 is palindrome, but square of 949 ( 900601 )isn't palindrome
959 is palindrome, but square of 959 ( 919681 )isn't palindrome
969 is palindrome, but square of 969 ( 938961 )isn't palindrome
979 is palindrome, but square of 979 ( 958441 )isn't palindrome
989 is palindrome, but square of 989 ( 978121 )isn't palindrome
999 is palindrome, but square of 999 ( 998001 )isn't palindrome
1001 is palindrome & square of 1001 ( 1002001 ) palindrome too
1111 is palindrome & square of 1111 ( 1234321 ) palindrome too
1221 is palindrome, but square of 1221 ( 1490841 )isn't palindrome
1331 is palindrome, but square of 1331 ( 1771561 )isn't palindrome
1441 is palindrome, but square of 1441 ( 2076481 )isn't palindrome
1551 is palindrome, but square of 1551 ( 2405601 )isn't palindrome
1661 is palindrome, but square of 1661 ( 2758921 )isn't palindrome
1771 is palindrome, but square of 1771 ( 3136441 )isn't palindrome
1881 is palindrome, but square of 1881 ( 3538161 )isn't palindrome
1991 is palindrome, but square of 1991 ( 3964081 )isn't palindrome
2002 is palindrome & square of 2002 ( 4008004 ) palindrome too
2112 is palindrome, but square of 2112 ( 4460544 )isn't palindrome
2222 is palindrome, but square of 2222 ( 4937284 )isn't palindrome
2332 is palindrome, but square of 2332 ( 5438224 )isn't palindrome
2442 is palindrome, but square of 2442 ( 5963364 )isn't palindrome


Create a new paste based on this one


Comments: