Swap via pointers and sort EASY Subprograme (BAC) 10 XP 0 solved
Mobile coding works. A laptop is faster for long sessions.

Problem

Write the definition of a subprogram `interschimba` that receives through two parameters, `a` and `b`, two pointers to integer values and swaps the values stored at the received addresses (so after the call, the value at address `a` is the original value from `b` and vice versa). Then write a main program that reads from standard input a non-zero natural number `n` and then `n` integers separated by spaces or newlines. The program prints the numbers sorted in ascending order, separated by single spaces, on a single line. **The sorting must be performed using exclusively calls to the subprogram `interschimba`** to swap elements of the array.

Input format

Input input.txt

The first line contains the natural number `n`. The following lines (separated by spaces or newlines) contain the `n` integers. - `1 <= n <= 100` - the values are integers with at most 4 digits (possibly with sign) - the subprogram `interschimba` must be defined explicitly, with parameters of pointer type (`int*`)

Output format

Output output.txt

The program prints to standard output the `n` numbers sorted in ascending order, separated by single spaces, followed by a newline.

Example

input
5
3 1 4 1 5
output
1 1 3 4 5

Ready to solve this challenge?

Create a free account to write code, submit solutions, and track your progress.

⌨️ Keyboard Shortcuts

Code Editor
Run Code
Ctrl Enter
Submit Code
Ctrl Shift Enter
Format Code
Shift Alt F
Toggle Comment
Ctrl /
Undo
Ctrl Z
Redo
Ctrl Y
Navigation
Global Search
/
Show Shortcuts
?
Close Modal
Esc

🔍 Interactive Debugger

0 / 0

Analyzing your code...

📦 Variables

No variables yet

📚 Call Stack
main() line 1
📤 Output
We use cookies

Essential cookies are always active. You can choose to enable preference and analytics cookies. Learn more