C program to check if a number is Armstrong or not
An Armstrong number is a number that is equal to the sum of cubes of its digits.
#include<stdio.h>
int main(){
int n, i, sum = 0, temp;
printf("Enter a number: ");
scanf("%d", &n);
temp = n;
while (n != 0)
{
i = n % 10;
sum = sum + i * i * i;
n = n / 10;
}
if (sum == temp){
printf("%d is an Armstrong number", temp);
}
else{
printf("%d is not an Armstrong number", temp);
}
return 0;
}
// Input: 153
// Output: 153 is an Armstrong number