Hey guys! I'm having a problem and I hope you guys can help me figure it out. I have to create a program that prints all the armstrong numbers from a user given lower and upper bound. I have a lot of the code but I can't seem to get a specific function right. The function is supposed to basically seperate a given number. So if x = 153, the function should seperate it into the numbers 1, 5, and 3. Problem is I have to seperate them and pass them to another function without an array. Here's what I have so far. The function I'm having problems with is called DthDigitofX.
//-----------------------------------------------------
int main()
//-----------------------------------------------------
{
boolean IsArmstrongNumber(int x);
int LB,UB,x;
printf("LB? "); scanf("%d",&LB);
printf("UB? "); scanf("%d",&UB);
for(x = LB; x <= UB; x++)
{
if(IsArmstrongNumber(x) == true)
printf("%i is an Armstrong Number", x);
}
system("pause");
return( 0 );
}
//-----------------------------------------------------
boolean IsArmstrongNumber(int x)
//-----------------------------------------------------
{
while (x >= 0)
{
int NumberOfDigits(int r);
int DthDigitOfX(int x,int d);
int sum,d,temp;
int n = NumberOfDigits(x);
for (d = 1; d <= n; d++)
{
sum = sum + pow(DthDigitOfX(x,d),n);
}
if(sum == x)
return true;
else
return false;
}
}
//-----------------------------------------------------
int NumberOfDigits(int x)
//-----------------------------------------------------
{
while(x >= 0)
{
int r = 0;
do
{
r++;
x /= 10;
//printf("%i\n", r);
}
while ( x != 0 );
return( r );
}
}
//-----------------------------------------------------
int DthDigitOfX(int x,int d)
//-----------------------------------------------------
{
while (x >= 0)
{
for (d = 1; d <= 10; d++)
x = x % 10;
return(x);
}
}