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!
Jonathan and Argyle have just finished snacking on their favorite treat—Palmtree Delight—a mysterious edible that makes them see everything in reverse! Suddenly, numbers appear backward, words are flipped, and even their memories seem to play in reverse order.
To test the effect, they decide to take an array of integers and reverse its order.
Write a function void reverse(int a[], int n) that receives an array a[] of size n and reverses the contents of the array.
The following limits are guaranteed in all the test cases that will be given to your program:
1 ≤ a[i] ≤ 1 000 | Numbers in the array | |
1 ≤ n ≤ 1 000 | 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 reverse(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); reverse(a, n); printf("reversed: "); print_array(a, n); return 0; }
Example Input | Example Output |
6 1 5 9 7 3 8 |
normal: [1,5,9,7,3,8] reversed: [8,3,7,9,5,1] |