蓝桥杯 基础练习 十进制转十六进制

源代码:
#include<stdio.h>
#include<stdlib.h>
typedef long long LL;
const LL N=100000;
char judge(LL );
int main(){
    LL a,i,ge,k=0;
    char b[N];
    scanf("%lld",&a);
    while(1){
        ge = a%16;
        b[k++]=judge(ge);
        a = a/16;
        if(a==0) {
            k--;
            break;
        }  //此处防止多输出一个0;此处容易出错
        if(a<16){
            b[k]=judge(a);
            break;
        }  //a<16,就不需要再向前判断了。
    }
    for(i=k;i>=0;i--)
        printf("%c",b[i]);
    return 0;
}
char judge(LL n){
    switch(n){
        case 0:return '0';
        case 1:return '1';
        case 2:return '2';
        case 3:return '3';
        case 4:return '4';
        case 5:return '5';
        case 6:return '6';
        case 7:return '7';
        case 8:return '8';
        case 9:return '9';
        case 10:return 'A';
        case 11:return 'B';
        case 12:return 'C';
        case 13:return 'D';
        case 14:return 'E';
        case 15:return 'F';
    }
}
 

 

相关文章:

  • 2021-12-06
  • 2022-01-18
  • 2021-08-25
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-24
  • 2021-06-10
  • 2021-10-25
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案