![]() |
|
[C] Fun C Challenge(Pointers, Random Integers, Arrays) - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [C] Fun C Challenge(Pointers, Random Integers, Arrays) (/showthread.php?tid=6194070) |
Fun C Challenge(Pointers, Random Integers, Arrays) - EmacsSucksButILikeIt - Feb 17, 2022 Fun C Challenge(Pointers, Random Integers, Arrays).. Here's a fun and standard C problem. Can you shuffle an array of integers via an array of int pointers? I.E. Say you have an array of integers: Code #define ARR_SIZE 10and an array of int pointers: Code #define ARR_SIZE 10Now can you use the addresses of the elements in arr to populate arr_ptrs such that each address in arr is present in arr_ptrs only once and is shuffled. Here's something to get you started: Code #include <stdio.h>Here is some examples of what the output of printing arr_ptrs would look like. Code (0): 8Code (0): 1Notice that each number from arr is represented and the output is shuffled. RE: Fun C Challenge(Pointers, Random Integers, Arrays) - unazed - Jun 4, 2022 a simple xorshift prng on the indices should be fine |