1つの自然数の7進数式は1つの3桁で、この自然数の9進数式も1つの3桁で、しかもこの2つの3桁のデジタルの順序はちょうど反対です.

1987 ワード

筋道がはっきりしていて、パッケージが合理的で、テストが完全で、linux GCC
#include 

typedef enum boolean{FALSE, TRUE}BOOL;

//this function is to find a natural num within 3,whoes
//7 decimal is the reverse to 9 decimal.

//function to calculate a Natural num to a decimal low euqal than 10.
//num the num that to be dealed.
//whichDecimal  what type of data you want such as HEX OCT or binary.
int ExchangeDecimal(int num, int whichDecimal)
{
    int tmp = 0;
    int multiRate = 1;
    while(num > whichDecimal)
    {
        tmp += (num % whichDecimal)*multiRate;
        num = num / whichDecimal;
        multiRate *=10;
    }
    tmp += num * multiRate;
    return tmp;
}
//reverse num 
int ReverseNum(int num)
{
    int cookData = 0;
    while(num > 0)
    {
        cookData *= 10;
        cookData += (num%10);
        num = num / 10;
    }
    return cookData;
}
//find the num and print the num
//num to be dealed ,num no big than 999 is required.
BOOL FindData(int num)
{
    int sevenDecimal = 0;
    int nineDecimal  = 0;
    int reverseNum   = 0;
    //first calculate the targetdecimal;
    sevenDecimal = ExchangeDecimal(num, 7);
    nineDecimal  = ExchangeDecimal(num, 9);
    //7 Decimal and 9 decimal not big than 999
    if(sevenDecimal>777 || nineDecimal >999)
        return FALSE;
    //reverse 9decimal
    reverseNum = ReverseNum(nineDecimal);
    if(sevenDecimal == reverseNum)
        printf("%d
",num); else return FALSE; } int main(int argc, char **argv) { if(argc < 3) { printf("Usage:
./a.out num decimal
"); return; } int num = atoi(argv[1]); int dec = atoi(argv[2]); printf("The input: %d
The Dec: %d",num,dec); printf("The output: %d
",ExchangeDecimal(num,dec)); printf("The reverse %d is %d
",num,ReverseNum(num)); int i = 999; while(i) { FindData(i); i--; } return 0; }