123. Funny Encryption Method

 avatar
user_6817964
c_cpp
3 years ago
542 B
5
Indexable
int bin(int N);
int hex(int N);


int bin(int N) {
    int count = 0;
    while (N > 0)
    {
        int temp = N % 2;
        if (temp == 1) {
            count++;
        }
        N /= 2;
    }
    return count;
}
int hex(int N) {
    int count = 0;
    while (N > 0)
    {
        int temp = N % 10;
        count += bin(temp);
        N /= 10;
    }
    return count;
}

int main() {
    int N, b1, b2;
    scanf("%d", &N);
    b1 = bin(N);
    b2 = hex(N);
    printf("%d %d", b1, b2);
    return 0;
}
Editor is loading...