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

This assignment is about Arrays: Complete the body of the function swap_arrays (

ID: 3636293 • Letter: T

Question

This assignment is about Arrays:

Complete the body of the function swap_arrays() in the program in below to swap the input arrays ar1 and ar2. Notice that these two formal parameters correspond to the actual parameters firstar and secondar in the main() function:

firstar

1

3

5

7

9

         0                       1                              2                              3                               4

secondar

2

4

6

8

10

         0                       1                              2                  3                       4

After executing the line (see main() function)

swap_arrays(firstar,secondar);

The two arrays will be swapped as shown below:

firstar

2

4

6

8

10

         0                       1                               2                            3                               4

secondar

1

3

5

7

9

         0                       1                              2                              3                               4

The Program which should be completed by swaping in below:

#include <stdio.h>

#define ARRAY_SIZE 5

void swap_arrays(int ar1[],int ar2[]);

int main()

{

int firstar[] = {1,3,5,7,9};

  int secondar[] = {2,4,6,8,10};

         

swap_arrays(firstar,secondar);

printf("Let us check that the swap was done successfully ");

printf("Printing the array firstar ");

for (int i=0;i < ARRAY_SIZE;i++)

printf("firstar[ %d] = %d ",i,firstar[i]);

printf("Printing the array secondar ");

  for (int i=0;i < ARRAY_SIZE;i++)

   printf("secondar[ %d] = %d ",i,secondar[i]);

           return 0;

}

void swap_arrays(int ar1[],int ar2[])

{

     

}

1

3

5

7

9

Explanation / Answer

void swap_arrays(int ar1[],int ar2[]) { int c[5],i; for(i=0;i