Skip to content

Instantly share code, notes, and snippets.

@wohhie
Created July 20, 2016 20:13
Show Gist options
  • Save wohhie/2df9f14f8b4cefb3317b33e4a9a72ea8 to your computer and use it in GitHub Desktop.
Save wohhie/2df9f14f8b4cefb3317b33e4a9a72ea8 to your computer and use it in GitHub Desktop.
Program to Check whether a given Number is Armstrong
//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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment