-
Notifications
You must be signed in to change notification settings - Fork 0
/
Activity: arrays and functions
29 lines (25 loc) · 1.1 KB
/
Activity: arrays and functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*Within this program, we will pass an array with 6 integers to a function, have the function swap the first and last integer, the second and the second to last integer, the third and the third to last integer.
The function is called reverseArray and doesn't return anything (void). It should take one parameter, representing the array of integers.
The main function first reads 6 integers from the input, and assigns them to the array. The main function then calls reverseArray, passing the array as an argument.
The main function then prints the reversed array.*/
#include <stdio.h>
void reverseArray(int *);
int main() {
int arr[6];
scanf("%d %d %d %d %d %d", &arr[0],&arr[1],&arr[2],&arr[3],&arr[4],&arr[5]);
reverseArray(arr);
printf("%d %d %d %d %d %d", arr[0],arr[1],arr[2],arr[3],arr[4],arr[5]);
return 0;
}
void reverseArray(int * ptr){
int array[6];
array[0]=ptr[0];
array[1]=ptr[1];
array[2]=ptr[2];
* ptr = * (ptr + 5);
* (ptr + 1) = * (ptr + 4);
* (ptr + 2) = * (ptr + 3);
* (ptr + 3) = array[2];
* (ptr + 4) = array[1];
* (ptr + 5) = array[0];
}