Question: Write a program swap.c that reads in an array of numbers, and swap the elements in the array such that the first and second elements

Write a program swap.c that reads in an array of numbers, and swap the elements in the array such that the first and second elements are swapped (the first element becomes the second and the second elements becomes the first), the third and fourth elements are swapped, and so on. If the array has an odd number of elements, the last element should remain unchanged. In the main function, ask the user to enter the length of the array, declare the array with the length, and swap the elements and display the array.

Example input/output #1:

Enter the length of the array: 5

Enter the elements of the array: 8 4 1 3 9

Output:

4 8 3 1 9

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!