C language to determine whether a number is Armstrong number (Armstrong number)

C language to determine whether a number is Armstrong number (Armstrong number)

Armstrong numbers, n-bit positive integers are equal to the sum of the nth power of each of their digits, as follows.:
153 = 1^3+5^3+3^3
1634 = 1^4+6^4+3^4+4^4

int is_armstrong(int v)
{
    int ov = v, t, ret = 0;

    while (ov) {
        t = ov % 10;
        ret += t * t * t;
        ov /= 10;
    }
	
	return (ret == v) ? 1 : 0;
}

Comments

Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example