Below is C program to Armstrong Numbers upto N.
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | /* Print Armstrong Numbers upto N */ #include<stdio.h> int main() { int i,j,sum,n; printf ( "Please enter the value of N: " ); scanf ( "%d" ,&n); for (i=2;i<=500;i++) { for (j=i,sum=n;j>=1;j=j/10) sum=sum+(j%10)*(j%10)*(j%10); if (sum==i) printf ( "%d is Armstrong.\n" ,i); } return 0; } |
No comments:
Post a Comment