Write a program that swaps the elements of an array pairwise. Start from the lef
ID: 3657685 • Letter: W
Question
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. 0 1 2 3 4 5 6 7 8 9 1 7 4 0 9 4 8 8 2 4 After pairwise swap you get the following array 0 1 2 3 4 5 6 7 8 9 7 1 0 4 4 9 8 8 4 2Explanation / 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]);
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.