what is the error in my code. it only gives false output
Armstrong number
Your approach is going wrong.
Say you are given a 4 digit number 1634
1634= 1^4 + 6^4 + 3^4 + 4^4 (So 1634 is an armstrong number)
Similarly:
153= 1^3 + 5^3 + 3^3 (So 153 is an armstrong number)
So by these examples you will get what an armstrong number is.
So to check if a number is armstrong number you just have to count the number of digits and extract each digit. Maintain a sum of (digit)^ noofdigits. If at the end of the loop, this sum==the given number then the number is armstrong else it is not armstrong.
now my code gives correct output but my two test cases are still not passed https://ide.codingblocks.com/s/228275
Still the same issue with your code.You code will give correct output only for 3digit numbers. For 4 digit numbers, you don’t have to take cubes. Read the above definition of Armstrong number as i have said.
can you please share the exact code of this problem.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.