In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of March 31st
(this exercise will still be available for submission after that deadline, but without couting towards your grade)
[to understand the context of this problem, you should read the class #04 exercise sheet]
In this problem you should submit a file containing the function as described (without any main function). Inside the function do not print anything that was not asked!
Eleven is practicing her telekinetic powers, but today, instead of flipping vans or breaking walls, she wants to organize numbers with her mind. She sees a jumbled array of integers floating in the air, and with a focused stare, she starts moving them into perfect order—smallest to largest.
Write a function void sort(int a[], int n) that receives an array a[] of size n and sorts its contents in ascending order.
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ a[i] ≤ 100 | Numbers in the array | |
1 ≤ n ≤ 100 | Size of the array |
You should submit a .c
file containing the requested function, without any main function and without printing anything. You can however create additional methods, if you need them.
Mooshak will use the following code to link to your function, read the inputs and call your method, printing its result.
#include <stdio.h> // Forward declaration of function to implement void sort(int [], int); // print an array of size n (assume size >= 1) void print_array(int a[], int n) { printf("[%d", a[0]); for (int i=1; i<n; i++) printf(",%d", a[i]); printf("]\n"); } int main(void) { // Read array of n integers int n; scanf("%d", &n); int a[n]; for (int i=0; i<n; i++) scanf("%d", &a[i]); // print array, call reverse and print array again afterwards printf("normal: ");print_array(a, n); sort(a, n); printf("sorted: ");print_array(a, n); return 0; }
Example Input | Example Output |
6 6 5 9 3 2 8 |
normal: [6,5,9,3,2,8] sorted: [2,3,5,6,8,9] |