Created
July 20, 2016 20:13
-
-
Save wohhie/2df9f14f8b4cefb3317b33e4a9a72ea8 to your computer and use it in GitHub Desktop.
Program to Check whether a given Number is Armstrong
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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