i am trying to write a program which displays the armstrong nos. between 1 and 999.
an armstrong no. is a no. which is equal to the sum of the cubes of its constituent digits. eg. 153=1^3+5^3+3^3
Code:
#include <stdio.h>
#include <math.h>
#define MAX_LIMIT 999
#define CUBE 3
int main(void)
{ int units=0,tens=0,no=0,hund=0;
for(no=1;no<=MAX_LIMIT;no++)
{
hund=no/100; //TO FIND THE HUNDREDS DIGIT
tens=(no%100)/10; //TO FIND THE TENS DIGIT
units=(no%100)%10; //TO FIND THE UNITS DIGIT
if(no==(pow(hund,CUBE))+(pow(tens,CUBE))+(pow(units,CUBE))) // ARMSTRONG CONDITION
printf("\n%d is a armstrong no.\n ",no);
}
return 0;
}
i want your reviews . are there simpler ways to solve this ?
i have another question.
before this concept i tried to get the digits of a no. using another concept.
a no. can be expressed as the sum of the product of the digits and their place values , like 135=(1*100)+(3*10)+(5*1)
so, i declared
Code:
int u,t,h,no;
(h*100)+(t*10)+(u*1)=no;
but, this gives an error lvalue required . why is it so?
please help!!