为什么我的程序显示任何输出......? [英] why doesnt my program display any output...?

查看:58
本文介绍了为什么我的程序显示任何输出......?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

该程序旨在找到最短的数字,当反转时(数字反转)=数字的两倍

the program is intended to find the shortest number which when reversed(digits are reversed) =twice the number

#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;
    }





添加缩进使其更具可读性 - OriginalGriff [/ edit]



[edit]Indentation added to make it more readable - OriginalGriff[/edit]

推荐答案

你认为有多少这样的数字?

一旦你超过50,就没有了:因为所有的2 * i值都有至少比原始号码多一个数字。

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 



低于50


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!


这篇关于为什么我的程序显示任何输出......?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆