1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
 
int card_convr(unsigned x, int n, char d[]) // x 변환하는 정수, n 기수
{
    char dchar[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    int digits = 0;
 
    if (x == 0)
        d[digits++= dchar[0];
    else
        while (x) {
            d[digits++= dchar[x%n];
            printf("%d |   %u - - - %d\n", n, x,x%n);
            printf("  +-----------------\n");
    
            x /= n;
        }
    printf("%10d\n", x);
    return digits;
}
 
int main(void)
{
    int i, cd, dno; // cd 기수, dno 변환후 자릿수
    unsigned no; //변환하는 정수
    char cno[512]; //변환한 값의 각 자리의 숫자를 저장하는 문자 배열
    int retry;
    printf("10진수를 기수 변환합니다.");
    do {
        printf("변환하는 음이 아닌 정수 : ");
        scanf("%u"&no);
        do {
            printf("어떤 진수로 변환할까요?(2-36):");
            scanf("%d"&cd);
        } while (cd < 2 || cd>36);
        dno = card_convr(no, cd, cno); //no를 cd진수로 변환
        printf("%d진수로는", cd);
        for (i = dno - 1; i >= 0; i--)
            printf("%c", cno[i]);
        printf("입니다.\n");
        printf("한 번 더 할까요 ? 1예 0아니요:");
        scanf("%d"&retry);
    } while (retry == 1);
 
    return 0;
 
    return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none;color:white">cs

+ Recent posts