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

Note: This assignement is depend upon the \"pelles c\" software programing. If y

ID: 3536052 • Letter: N

Question

Note: This assignement is depend upon the "pelles c" software programing. If you're welling to answer I'd like to send the ansewr as a notepad afetr compeleting the program.

This assignment is about Arrays(Chapter 8).

Complete the body of the function swap_arrays() in the program on page 3 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


#include<stdio.h>

#define ARRAY_SIZE 5

voidswap_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;

}

voidswap_arrays(int ar1[],int ar2[])

{

}

1

3

5

7

9

Explanation / Answer

#include<iostream.h>

void swap(int *a[],int *b[]);

void main()

{

int a[10],b[10],i;

cout<<'Enter element of array 1";

for(i=0;i<10;i++)

cin>>a[i];

cout<<'Enter element of array 2";

for(i=0;i<10;i++)

cin>>b[i];

swap(&a,&b);

cout<<"First array is "

for(i=0;i<10;i++)

cout<<a[i];

cout<<"second array is "

for(i=0;i<10;i++)

cout<<b[i];


}


void swap(int *a[],int *b[])

{

int c[10];

for(i=0;i<10;i++)

{

c[i]=a[i];

a[i]=b[i];

b[i]=c[i];

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote