Answer to Question #263892 in C for Sam

Question #263892

Write a program that



1. Contains a function that displays the content of an integer array starting from the upper bound on a single line.



2. Contains a function that swaps the first and last elements of an integer array. For


example, 1 4 9 16 25 would be transformed into 25 4 9 16 1.



3. Test the functions in (1) and (2) with the aid of an initialized array of your choice in the main function. Display the array before and after the shifting of the elements.



1
Expert's answer
2021-11-10T14:51:08-0500
void Display(int *arr, int n)
{
	int i;
	printf("\n\tArray before modification: ");
	for (i = 0; i < n; ++i) printf("%d, ",*(arr+i));
}


void SwapArrayEnds(int *arr, int n)
{
	int x;
	x = *(arr+n-1);
	*(arr+n-1) = *(arr+0);
	*(arr+0) = x;
}


int main() 
{
	int ArraySize;
	int Array[] = {25, 4, 9, 16, 1};
	int i;
	int userNum;
	
	ArraySize = sizeof(Array)/sizeof(Array[0]);
	Display(&Array[0],ArraySize);
	
	SwapArrayEnds(&Array[0], ArraySize);
	printf("\n\tArray after modification : ");
	for (i = 0; i < ArraySize; ++i) 
	{
		printf("%d, ",Array[i]);
	}
	
	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
APPROVED BY CLIENTS