If i want the output like:
1st Armstrong number = 0
2nd Armstrong number = 1
3rd Armstrong number = 153
.............................................
.............................................
20th Armstrong number = ....
here my question is : if i have to print many armstrong numbers(1st to 20th) then is it the proper way to write printf one by one ? then i need to much time & code will be so long,how i minimize it?
please help....
This is my code which is able to find first 6 Armstrong Number..
int main(){
int a, b, c, num, i=0,j=0;
printf("Printing all the armstrong numbers between 1 - 999");
while(i<=999)
{
a= i/100;
a= a*a*a;
num= i%100;
b= num/10;
b= b*b*b;
c= num%10;
c=c*c*c;
if(i==a+b+c)
{
j++;
if(j==1) printf("\n1st");
else if(j==2) printf("\n2nd");
else if(j==3) printf("\n3rd");
else if(j==4) printf("\n4th");
else if(j==5) printf("\n5th");
else if(j==6) printf("\n6th");
printf(" Armstrong number= %d",i);
}
i++;
} // end of while
return 0;
} // end of main