Answer to Question #303310 in C++ for ehsan

Question #303310

write c++ programm to swap first and last element of an integer 1-D array


1
Expert's answer
2022-02-27T03:58:17-0500
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);	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog