<什么是数学>第一章习题

1.用以a=2,3,...,15为底,给0到1000的数字起名字,需要多少个不同的数字的名称?哪一种基底要求的数字名称最少?

写了个小程序来测试,答案是4,需要8个数字名称.

 

#include <stdio.h>
#define START_BASE 2
#define BASE_LIMIT 16
#define NUMBER 1001

int main(void)
{
    int min_number_base = START_BASE;
    int min_number_count = NUMBER;
   
    int base;
    int count;
    int product;
    for(base=START_BASE; base < BASE_LIMIT; base++)
    {
        count = base;
        product = 1;
        while((product *= base) < NUMBER)
        {
            count++;
        }
        if (count < min_number_count)
        {
            min_number_base = base;
            min_number_count = count;
        }
        printf("base:%d\n",base);
    }
   
    printf("The min number of base is: %d\n",min_number_base);
    printf("The count is: %d\n",min_number_count);

 

待续.......

 

posted @ 2011-05-02 17:40  十三  阅读(412)  评论(0编辑  收藏  举报