c_cpp 程序检查给定的数字是否是阿姆斯特朗

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 程序检查给定的数字是否是阿姆斯特朗相关的知识,希望对你有一定的参考价值。

//C Program to Check whether a given Number is Armstrong
#include <math.h>
#include <stdio.h>

int main() {
	
	int rem,
		sum = 0,
		cube,
		temp,
		num,
		i;

	printf("Enter a number to check Armstrong: ");
	scanf("%d", &num);

	temp = num;
	

	while (num != 0) {

		rem = num % 10;	// 153 to rem = 3 (last digit)
		cube = pow(rem, 3);	//3**3
		sum = sum + cube;	// 0 + 27
		num = num / 10;
	}

	if (sum == temp) {
		printf("\nThis number is Armstrong number.\n");

	}
	else {
		printf("\nThis number is not Armstrong number.\n");
	}

	return 0;
}

以上是关于c_cpp 程序检查给定的数字是否是阿姆斯特朗的主要内容,如果未能解决你的问题,请参考以下文章