Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(USING VISUAL STUDIOS & C Programming) 3) (5 pts) Arrays & Functions : Write a f

ID: 3600350 • Letter: #

Question

(USING VISUAL STUDIOS & C Programming)

3) (5 pts) Arrays & Functions: Write a function:

areverse(int a[], int size)

to reverse the order of the elements in the integer array input a[]. That is, swap the first and last elements, 2nd and next-to-last, etc...

Also write a main() program to test it, which prompts the user to enter numbers (terminated with a non-numeric), puts them into an array, then prints the array elements in the original order, calls the areverse()function, and then prints them in the reversed order

Explanation / Answer

#include <stdio.h>
void areverse(int a[], int size) {
int i, t;
for(i=0;i<size/2;i++) {
t = a[i];
a[i]=a[size-1-i];
a[size-1-i] = t;
}
}
int main()
{
int a[50], i, n,j;
printf("Enter the number(-1 to quit):");
scanf("%d", &n);
while(n != -1){
a[i]=n;
i++;
scanf("%d", &n);
}
printf("Array elements are: ");
for(j=0;j<i;j++){
printf("%d ",a[j]);
}
printf(" ");
areverse(a, i);
printf("Array elements are after reverse: ");
for(j=0;j<i;j++){
printf("%d ",a[j]);
}
printf(" ");

return 0;
}

Output: