How to swap numbers any number of digits in JavaScript and c++ ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to swap numbers any number of digits in JavaScript and c++ ?

18th Dec 2018, 2:15 PM
Akash S P
Akash S P - avatar
2 Answers
+ 8
1) Make a temporary variable 2) Store value of first variable in temporary variable 3) Assign value of second variable to first variable 4) Assign value of temporary variable to second variable
18th Dec 2018, 7:19 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 2
If asking to change 123 to 321: Make the output variable (string or integer) For each digit,... Get the digit Put it into place in output Endfor Strings are the easiest to process as integers require math to get each digit where string can just be indexed.
18th Dec 2018, 7:53 PM
John Wells
John Wells - avatar