24th May 2021, 3:39 PM
Ira Sarkar
Ira Sarkar - avatar
20 Answers
+ 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.
24th May 2021, 3:53 PM
Lothar
Lothar - avatar
+ 5
Store the value of n in another variable and then use it in the if statement.
24th May 2021, 3:50 PM
Soumik
Soumik - avatar
+ 3
Move `t = n;` after reading value of <n> through `scanf()`, not before.
24th May 2021, 4:27 PM
Ipang
+ 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
24th May 2021, 3:50 PM
Arsenic
Arsenic - avatar
+ 2
Also <arm> is not initialized by zero. Local variables are not guaranteed a default value, it's better to initialize them.
24th May 2021, 3:55 PM
Ipang
+ 2
Ira Sarkar this will only work if the input number is a 3 digit number ( see Lothar 's responce )
24th May 2021, 3:58 PM
Arsenic
Arsenic - avatar
+ 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.
26th May 2021, 11:46 AM
Kavya N
Kavya N - avatar
+ 1
What are you trying to do? Variable arm changed on each step of cycle. n and arm compared after all steps(n=0).
24th May 2021, 3:53 PM
Igor Kostrikin
Igor Kostrikin - avatar
+ 1
Lothar okay, what should I do
24th May 2021, 3:56 PM
Ira Sarkar
Ira Sarkar - avatar
+ 1
Ipang thanks 😅 😅 I solved it tho
24th May 2021, 4:28 PM
Ira Sarkar
Ira Sarkar - avatar
+ 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.
25th May 2021, 6:39 PM
Wheres8
Wheres8 - avatar
+ 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.
25th May 2021, 7:03 PM
Wheres8
Wheres8 - avatar
+ 1
Wheres8 sorry, thank you.
25th May 2021, 7:15 PM
Ira Sarkar
Ira Sarkar - avatar
+ 1
Just code dont give up You do good
27th May 2021, 9:24 AM
Isabel Bernal
Isabel Bernal - avatar
0
Soumik [Busy] Arsenic Still not working
24th May 2021, 3:56 PM
Ira Sarkar
Ira Sarkar - avatar
0
Arsenic i put 153
24th May 2021, 3:59 PM
Ira Sarkar
Ira Sarkar - avatar
0
Wheres8 it's working just fine, if you haven't checked the result. I forgot to delete the question.
25th May 2021, 6:53 PM
Ira Sarkar
Ira Sarkar - avatar
0
Kavya N its working 😅 Forgot to delete
26th May 2021, 1:49 PM
Ira Sarkar
Ira Sarkar - avatar
0
Isabel Bernal oh my god, thank you so much
27th May 2021, 9:34 AM
Ira Sarkar
Ira Sarkar - avatar
- 1
Armstrong nos are in 3digits only
24th May 2021, 3:59 PM
Ira Sarkar
Ira Sarkar - avatar