/*why i'm getting only 1 and 0?Code:/*PROGRAM TO PRINT ARMSTRONG NUMBERS FROM 1 TO 1500*/ #include<stdio.h> #define boundary 1500 *FUNCTION TO FIND X^N*/ int raise(int x,int n) {if(n==1) return x; return x*raise(x,n-1); } /*FUNCTION TO ADD DIGITS*/ long int sum(int n,int noofdigit) { int temp; static long int sum1=0; sum1+=raise(n%10,noofdigit); if(n/10!=0) sum(n/10,noofdigit); else return sum1; } /*FUNCTION TO FIND NUMBER OF DIGITS*/ int digitn(int n) {int i; for(i=1;n/10!=0;++i) n/=10; return i; } /*FUNCTION FOR CHECKING WHETHER NUMBER IS ARMSTRONG*/ void armstrong() { int i,a,digits; for(i=0;i<=boundary;++i) if(sum(i,digitn(i))==i) printf("%d ",i); printf("\n"); } main() { printf("ARMSTRONG NUMBERS IN FIRST 1500 NUMBERS ARE: "); armstrong(); }
I'm working in linux not TC
*/