C Program to check a number is Armstrong or not using the function
In this program, You will learn how to check a number is Armstrong or not using a function in c.
Some list of Armstrong numbers is: 153, 370, 371, 407
Example: How to check a number is Armstrong or not using a function in c.
#include<stdio.h>
int check(int n) {
int r, arm = 0;
while (n > 0) {
r = n % 10;
arm = arm + r * r * r;
n = n / 10;
}
return arm;
}
int main() {
int n, arm;
printf("Enter a number:");
scanf("%d", &n);
arm = check(n);
if (arm == n) {
printf("Number is Armstrong:%d", n);
} else {
printf("Number is not Armstrong:%d", n);
}
return 0;
}
Output:
Enter a number:153
Number is Armstrong:153