This is the code to print all armstrong numbers within a range m to n as input by the user. But when i run it, it does not give proper output. Suppose i input m as 1 and n as some 10000, it only shows '1 is armstrong' and nothing else.Please tell me if something is wrong in my code.
#include<stdio.h> void main() { int m,n,a,i,j=0,r; printf("Enter m\n"); scanf("%d",&m); printf("Enter n\n"); scanf("%d",&n); for(i=m;i<=n;i++) { int temp=i; while(i>0) { r=i%10; j=j+r*r*r; i=i/10; } if(j==temp) { printf("%d is armstrong\n",temp); } } }
iboth in the for loop (i++) and also in the while loop (i=i/10;). It means your for-loop will not run across all values frommton.