write c++ programm to swap first and last element of an integer 1-D array
The Answer to the Question
is below this banner.
Can't find a solution anywhere?
NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?
Get the Answers Now!You will get a detailed answer to your question or assignment in the shortest time possible.
Here's the Solution to this Question
using namespace std;
//write c++ programm to swap first and last element of an integer 1-D array
int main()
{
int arr[]={1,3,5,7,9};
int n=0,l;
l = sizeof(arr)/sizeof(arr[0]);
cout<<"\n\tArray before swapping: ";
for(n=0;n<l;n++) cout<<arr[n]<<", ";
n=arr[0]; arr[0] = arr[l-1]; arr[l-1] = n;
cout<<"\n\tArray before swapping: ";
for(n=0;n<l;n++) cout<<arr[n]<<", ";
return(0);
}