Skip to content

Commit

Permalink
armstrong number
Browse files Browse the repository at this point in the history
  • Loading branch information
anjalijp committed Oct 3, 2020
1 parent d108405 commit d1dd0d3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions C/armstrong.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
void main() {
int n, originalNum, rem, result = 0;
printf("Enter a three-digit integer: ");
scanf("%d", &n);
originalNum = n;

while (originalNum != 0) {
// remainder contains the last digit
rem = originalNum % 10;

result += rem * rem * rem;

// removing last digit from the orignal number
originalNum /= 10;
}

if (result == n)
printf("%d is an Armstrong number.", n);
else
printf("%d is not an Armstrong number.", n);

}

0 comments on commit d1dd0d3

Please sign in to comment.