Write a C program to check Armstrong Number of N digits
Sample input : 153
Sample output: armstrong number
Sample input : 1634
Sample output : armstrong number
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include <stdio.h> #include <math.h> int arm(int a) { int i=0,res=0,dup,rem; dup=a; while(dup!=0) { dup= dup/10; ++i; // To find how many digits present } dup=a; while(dup!=0) { rem=dup%10; res+=pow(rem,i); dup=dup/10; } return res; } int main() { int n,c; scanf("%d",&n); c=arm(n); if(c==n) { printf("armstrong number"); } else { printf("not a armstrong number"); } return 0; } |
OUTPUT:
0 comments