Guys what are the various ways to convert any integer values into an integer array...? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Guys what are the various ways to convert any integer values into an integer array...?

19th Aug 2017, 11:39 AM
Master Gaurav
Master Gaurav - avatar
10 Answers
20th Aug 2017, 3:55 AM
pratheek shenoy k
+ 1
c++: #include <array> int toConvert; array<int> arr = { toConvert }; java: int toConvert; int[] arr = { toConvert };
19th Aug 2017, 3:38 PM
Timon Paßlick
0
we can use % to get individual elements and than save in a array
19th Aug 2017, 2:40 PM
pratheek shenoy k
0
@Timom i want to store that no. individually in array.. like 125 --> 1,2,5
20th Aug 2017, 3:15 AM
Master Gaurav
Master Gaurav - avatar
0
Ok, try doing that yourself with c++, it's fun. Hint: use modulo and division to get the digits. Try it first with 3 digits, then with n digits (hint: vector) and then make the whole thing a template function. I'll do the same thing. When you're done, I'll make my code public and we can compare.
20th Aug 2017, 6:51 AM
Timon Paßlick
0
Done.
20th Aug 2017, 8:01 AM
Timon Paßlick
0
Your solution prints the digits in reverse order, pratheek shenoy k. ) :
20th Aug 2017, 8:07 AM
Timon Paßlick
0
You need pow of the <math> header for the last 2 steps, Gaurav.
20th Aug 2017, 8:08 AM
Timon Paßlick
0
yes it gives in reverse order, we can access the array as we want by changing the for loop
20th Aug 2017, 9:49 AM
pratheek shenoy k
0
Yes, ok. I thought you didn't test it and that this would be a semantic error. Sorry.
20th Aug 2017, 10:12 AM
Timon Paßlick