View Code of Problem 3805

#include <stdio.h>
int judge(int n, int m, int k)
{
    int a[5], i, sum, x;
    x = n; sum = 0;
    for (i = 0;; i++)
    {
        a[i] = x % m;
        sum += a[i];
        x /= m;
        if (x == 0)
            break;
    }
    if (sum == k)
        return 1;
    else
        return 0;
}
int main()
{
    int n, k, a[5], sum, x, i;
    while (scanf("%d", &n), n)
    {
        sum = 0;
        x = n;
        for(i=0;;i++)
        {
            a[i] = x % 10;
            sum += a[i];
            x /= 10;
            if (x == 0)
                break;
        }
        if (judge(n, 12, sum) == 1 && judge(n, 16, sum) == 1)
            printf("%d is a GOD number.\n", n);
        else
            printf("%d is not a GOD number.\n", n);
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 3805