AToI&IToA

//AToI
#include <stdio.h>
#define SIZE 200
int data[SIZE] = {4,5,6,7};

int AToI(int N,int Base)
{
    int ret = 0;
    for(int i=0;i<N;i++)
    {
    ret = ret * 10 + data[i];
    }
    return ret;
}

int main(void)
{
    int num = AToI(4,10);
    printf("%d",num);
    return 0;
}
//IToA
#include <stdio.h>
#define SIZE 20
int data[SIZE];

int IToA(int num,int Base,int Len)
{
    for(int i=Len-1;i>=0;i--)
    {
        data[i] = num % Base;
        num /=10;
    }
}

int main(void)
{
    int num = 10786;
    IToA(num,10,5);
    for(int i =0; i<5;i++)
        printf("%d",data[i]);
    return 0;
}

 

posted @ 2017-04-01 14:11  xcsllll  阅读(92)  评论(0编辑  收藏  举报