Click here to Skip to main content
15,921,382 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
the program is intended to find the shortest number which when reversed(digits are reversed) =twice the number
C#
#include<stdio.h>
int palindrome(int x);
int main()
    {
    int i;
    for(i=1;i<=1000000;i++)
        {
        if(2*i==palindrome(i))
            {
            printf("%d",i);
            break;
            }
        }
    return 0;
    }
int palindrome(int x)
    {
    int rem,res=0;
    while(x>0)
        {
        rem=x%10;
        res=res*10+rem;
        x=x/10; 
        }
    return res;
    }


[edit]Indentation added to make it more readable - OriginalGriff[/edit]
Posted
Updated 9-Jan-15 8:06am
v3
Comments
joshrduncan2012 9-Jan-15 14:14pm    
Have you tried debugging this to see if you actually get in the if(2*i==palindrome(i)) statement?
Member 11324568 10-Jan-15 13:44pm    
yes @john...there are actually no such numbers thats why there is no output display and when i type in palindrome=i*4 there is output...

1 solution

And how many such numbers do you think there are?
Once you get over 50, there aren't any: because all the 2 * i values have at least one more digit that the original number.
50 * 2 == 100 

And below 50
 i  2i  palendrome(i)
 1,  2, 1
 2,  4, 2
 3,  6, 3
 4,  8, 4
 5, 10, 5
 6, 12, 6
 7, 14, 7
 8, 16, 8
 9, 18, 9
10, 20, 1
11, 22, 11
12, 24, 21
13, 26, 31
14, 28, 41
15, 30, 51
16, 32, 61
17, 34, 71
18, 36, 81
19, 38, 91
20, 40, 2
21, 42, 12
22, 44, 22
23, 46, 32
24, 48, 42
25, 50, 52
26, 52, 62
27, 54, 72
28, 56, 82
29, 58, 92
30, 60, 3
31, 62, 13
32, 64, 23
33, 66, 33
34, 68, 43
35, 70, 53
36, 72, 63
37, 74, 73
38, 76, 83
39, 78, 93
40, 80, 4
41, 82, 14
42, 84, 24
43, 86, 34
44, 88, 44
45, 90, 54
46, 92, 64
47, 94, 74
48, 96, 84
49, 98, 94
And there are no values in that list which pass your criteria either...

So you code is doing what it should: not showing anything!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900