当前位置:操作系统 > 安卓/Android >>

十进制转十六

[cpp] 
#include <iostream> 
#include <cstdio> 
#define M 1000 
using namespace std; 
int k = 0; 
char a[20] = {'0','1','2','3','4','5','6','7','8','9','A', 
             'B','C','D','E','F'}; 
int change(int num, char *p){ 
    int m; 
    while(num){ 
        m = num%16; 
        num = num/16; 
        p[k++] = a[m]; 
    } 
    return 1; 

 
int main() 

    int val; 
    char temp[M]; 
    printf("please input a num:\n"); 
    scanf("%d", &val); 
    change(val, temp); 
    for(int j = k-1; j >= 0; j--){ 
        printf("%c",temp[j]); 
    } 
    printf("\n"); 
    return 0; 

补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,