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

1. (100 pts) Write a program that swaps the elements of an array pairwise. Start

ID: 3760487 • Letter: 1

Question

1. (100 pts) Write a program that swaps the elements of an array pairwise. Start from the left of the array, take 2 elements at a time and swap the two elements. Continue in this fashion until you reach the end of the array. Declare an integer array of size 10 and place random numbers in the range [0-9]. Print the original array, pairwise swap the elements of the array and print the final array after swap. Consider the following example. After pairwise swap you get the following array In the array first two numbers 1 and 7 are swapped, 4 and 0 are swapped, 9 and 4 are swapped, 8 and 8 are swapped and 2 and 4 are swapped. Sample execution of the program is given below Original array 1 7 4 0 9 4 8 8 2 4 After pairwise swap 7 1 0 4 4 9 8 8 4 2

Explanation / Answer

#include<stdio.h>

void main()

{

int arr[10],i,temp;

printf("enter value in array ");

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

scanf("%d",&arr[i]);



\ change position


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

{

temp=arr[i];

arr[i]=arr[i+1];

arr[i+1]=temp;

}


printf(" change value in array is ");

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

printf("%d ",arr[i]);


}