write c++ programm to swap first and last element of an integer 1-D array
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);
}
Comments
Leave a comment