100c之22:计算车速

Table of Contents

问题

一辆车匀速行驶,司机上午十点看里程表上的读数是一个对称数,即这个数从左到右和从右到左读是完全一样的。这个数是95859。两个小时后出现了一个新的对称数,问该车的车速是多少,新的对称数是多少?

分析

此题很容易。其实不用计算机,自己猜测也可以才得到,最近的一个回文数是95959.车速是100.

解决方案

 1:  /**
 2:   * @file   022thespeed.c
 3:   * @author Chaolong Zhang <emacsun@163.com>
 4:   * @date   Wed May 22 19:17:55 2013
 5:   * 
 6:   * @brief 
 7:   */
 8:  
 9:  #include <stdio.h>
10:  
11:  int main(int argc, char *argv[])
12:  {
13:    int n;
14:    for (n=95860;  n < 100000; ++n)
15:    {
16:      if ((n%10 == n/10000) && ( n/10%10 == n/1000%10 ) )
17:      {
18:        printf ("the number is %d and the speed is %f\n", n, (float)(n-95859)/2 ); break;
19:      }
20:      else continue;
21:    }
22:    return 0;
23:  }
posted @ 2013-05-22 19:35  emacsun  阅读(234)  评论(0编辑  收藏  举报