+ 3
Why its not working?
20 Respuestas
+ 6
Ira Sarkar ,
i think the problem is this expression:
arm=arm+ pow(rem,3);
the second argument for pow() function depends on the count of digits of the input number. 3 is only valid for numbers of length 3.
+ 5
Store the value of n in another variable and then use it in the if statement.
+ 3
Move `t = n;` after reading value of <n> through `scanf()`, not before.
+ 2
You are destroying your original input integer "n" while calculating "arm"
One possible fix is to store it's value in some other variable and perform calculations on it instead. 👇
https://code.sololearn.com/chrx4Two2ycT/?ref=app
+ 2
Also <arm> is not initialized by zero. Local variables are not guaranteed a default value, it's better to initialize them.
+ 2
Ira Sarkar this will only work if the input number is a 3 digit number ( see Lothar 's responce )
+ 2
It's working!!
I think you were giving wrong input for Armstrong number.
A given number becomes Armstrong number only when cubes of all digits present is equal to the number.
Eg : n = 153
1^3 + 5^3 + 3^3 = 1+125+27 = 153
Which is equal to n.
Hope its clear for you.
+ 1
What are you trying to do? Variable arm changed on each step of cycle. n and arm compared after all steps(n=0).
+ 1
Lothar okay, what should I do
+ 1
Ipang thanks 😅 😅
I solved it tho
+ 1
Additionally to what others have said, please format your source code(s) properly! Its very difficult/unpleasant to read. Don't declare multiple variables, especially with different meanings, on the same line, and if you're going to do it anyway, add at least one space between every declaration.
Secondly add spaces between initilisations and comparisons (for example the while loop -> t!=0 should rather be t != 0 or !(t == 0) or even !t (since t alone in while is asking for trueness and 0/! is the same as false).
Same thing for printfs, scanfs and when you add arm+= ... in the loop, first you dont add space, then all of a sudden you do. That's not consistency.
+ 1
Ira Sarkar I did not comment on the functionality. Re-read my comment I am talking about your formating / style of coding.
X11 works (sometimes) but that doesn't mean it's readable by human beings.
+ 1
Wheres8 sorry, thank you.
+ 1
Just code dont give up
You do good
0
Soumik [Busy]
Arsenic
Still not working
0
Arsenic i put 153
0
Wheres8 it's working just fine, if you haven't checked the result.
I forgot to delete the question.
0
Kavya N its working 😅
Forgot to delete
0
Isabel Bernal oh my god, thank you so much
- 1
Armstrong nos are in 3digits only