10 진 변환 16 진

#include<stdio.h>
#define N 8
#define k 16
void tran(int num) 
{ 
    int arr[N],i; 
    for (i=0;i <N;i++) 
    { 
        arr[i]=num%k; 
        num=num/k; 
        if (num==0) 
            break; 
    } 
    printf("   %d    : ",k); 
    for (;i>=0;i--) 
        switch (arr[i]) 
        { 
        case 10: printf("A");break; 
        case 11: printf("B");break; 
        case 12: printf("C");break; 
        case 13: printf("D");break; 
        case 14: printf("E");break; 
        case 15: printf("F");break; 
        default: printf("%d",arr[i]); 
        } 
    printf("
"); } int main() { int num; printf(" :
"); scanf("%d",&num); tran(num); return 0; }

좋은 웹페이지 즐겨찾기