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

In C programming language Create a program that does the following: -In the main

ID: 3747413 • Letter: I

Question

In C programming language

Create a program that does the following: -In the main method swap the arrays. -Print the arrays before and after the swap. //output should look like the following Before Swap firstArrayl0]-0, secondArray[O] 1 firstArray[1] 2, secondArray[1] 3 firstArray[2 4, secondArray[2] 5 firstArray[3 6, secondArray[3 7 firstArrayl4]-8, secondArray[4]-9 After Swap firstArray[0] 1, secondArray[O] 0 firstArray[1] 3, secondArray[1] 2 firstArray[2]-5, secondArray[2] 4 firstArrayl3 7, secondArray[3] 6 firstArray 4] 9, secondArray[4] 8

Explanation / Answer

Hi,here below is the solution of the program.Kindly go through that .

#include<stdio.h> /*we are including the standard headerfile here with #include preprocessor derective */

#define MAX 5 /* it is a macro we are including with 'MAX" macro name and macro expanssion is of 5,so that our compiler will replace this macro value with 5 when it will see a MAX word in our code */

int main()

{

int i; /*here we are declaring an interger ,which we are going to use in our loop shortly */

int firstArray[MAX] = {0,2,4,6,8}; /*this is our 1st array of even numbers ,and as per the output given above i have limited my array elemnts to 5 elements and

MAX will take care of that arrayboundary */

int secondArray[MAX] = {1,3,5,7,9}; /*this is our 2nd array of 5 odd elements */

printf("before swap "); /* this statement is to print only before swap */

for(i=0;i<MAX;i++) /*in this loop we are initialising our variable with 0,so that it will start reading { from 0 index to less than MAX,which is our array limit, and after each loop the i value will be increamented */

printf("firstArray[i] = %d,secondArray[i] = %d ",firstArray[i],secondArray[i]); /*printf the elments of first and second array before swap */

}

/*below we are using size of operator to get the size of two array and compair it,if the condition becomes true then it will get into the loop and swap all elements of two array.it is important to check when we swap array of diferent different size */

if( sizeof (firstArray) == sizeof (secondArray) )

{

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

{

int temp ; /*we will be using this variable for swap operation */

/*within this loop we have taken one temporary variable ,in which we will staore firstArray[0] th variable then ,in firstArray[0] th place we will store secondArray[0] th variable and then in secondArray[0] the position temp value will be stored.that means it will go like a cyclic way to swap to array elements and till the i Value will become MAX-1 */

temp = firstArray[i];

firstArray[i] = secondArray[i];

secondArray[i] = temp;

}

}

printf("after swap "); /* ' ' indicates new line */

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

{

/*this below statement will print the values of 2 array after swap */

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

}

return 0;

}