[ Write in C not C++]
Define a C function void placeElements(int *a, int i, int j)
that
inter-exchange the array elements at indexiandj. For a[] =
{5,7,4,2,1},a
callto placeElements(a,2,4) makesa[] = {5,7,1,2,4}. [8]
#include <stdio.h> void placeElements(int *a, int i, int j); int main() { int a[] = {5, 7, 4, 2, 1}, i; for (i = 0; i < 5; ++i) { printf("%d ", a[i]); } printf("\n"); placeElements(a, 2, 4); for (i = 0; i < 5; ++i) { printf("%d ", a[i]); } printf("\n"); return 0; } void placeElements(int *a, int i, int j) { int temp = a[i]; a[i] = a[j]; a[j] = temp; }
Get Answers For Free
Most questions answered within 1 hours.