趣味100道C语言编程题num seven

求车速:一辆以固定速度行驶的汽车,司机在上午10点看到里程表上的读数是一个对称数(即这个数从左向右读和从右向左读是完全一样的),为95859.两个小时后里程表上出现了一个新的对称数。问该车的速度是多少?新的对称数是多少?

#include 
#define MAX_SIZE 1024

int image_num(int num)
{
    int i = 0;
    int wei = 0;
    int flag = 0;
    int mid[MAX_SIZE];

    while(num > 0)
    {
        wei++;
        mid[i++] = num % 10;
        num = num / 10;
    }

    for(i = 0;i <= wei / 2;i++)
    {
        if(mid[i] != mid[wei - i - 1])
        {
            flag = 1;
            break;
        }
    }
    return flag;
}

int main(void)
{
    int i;
    int num;
    int flag;
    float speed;

    for(i = 95860;flag;i++)
    {
        flag = image_num(i);
        num = i;
    }
   
    speed = (num - 95859) / 2.0;

    printf("The speed of the car is:%.2f\n",speed);
    printf("The new image number is:%d\n",num);

    return 0;
}

调试结果为:
The speed of the car is:50.00
The new image number is:95959



你可能感兴趣的:(趣味100道C语言程序题)