I'm trying to find whether a number is an armstrong number or not, but first, I want to find the armstring value (each digit of the number must be powered to the number of digits in the number). For instance, if 9474 was the value, we should do 9^4(4 is the number of digits in the number) + (4^4) + (7^4) + (4^4) = 9474.
Some useful facts about my code:
digitcount
counts the digit to be squaredb
is intended to be the armstrong value
Here is my code so far:
#include <stdio.h>
void main(){
int b,remainder, digitcount, i, j;
digitcount = 0;
printf("Enter a value for i: ");
scanf("%d", &i);
b = 0;
remainder = 1;
while (i != 0){
i = i/10;
++digitcount;
}
printf("%d", digitcount);
for (j = 1; j <= digitcount; j++){
while (i != 0){
while (digitcount != 0){
remainder = (i % 10)*= digitcount;
b = b+remainder;
i = i/10;
digitcount--;
}
}
}
printf("%d", b);
}
When I put in 9474 for this, my answer yields an error "Invalid value on assignement".
I've been trying to debug this, but to no avail. what should I change in my code?