63 223
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #62741 in C for Naveena

Question #62741
write a c program to find out number is armstrom or not??
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions