Answer to Question #62741 in C for Naveena

Question #62741
write a c program to find out number is armstrom or not??
1
Expert's answer
2016-10-20T12:30:11-0400
#include <stdio.h>

int power(int a, int n) {
int res = 1, i;

for (i = 0; i < n; i++) {
res *= a;
}

return res;
}

int isArmstrongNumber(int n) {
int res = 0, m, numOfDigits = 0;
m = n;
do {
numOfDigits++;
m /= 10;
} while (m);

m = n;
do {
int d = m % 10;
m /= 10;
res += power(d, numOfDigits);
} while (m);

return (res == n);
}

int main() {
int n;
scanf("%d", &n);

printf(isArmstrongNumber(n) ? "YES\n" : "NO\n");

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS