Answer to Question #62741 in C for Naveena
2016-10-18T13:36:12-04:00
write a c program to find out number is armstrom or not??
1
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 !
Learn more about our help with Assignments:
C
Comments
Leave a comment