Answer to Question #267596 in C++ for Yasir

Question #267596

Create a dynamic array of user defined size. Now move the largest number in the array to first position. Print the array after moving the number. All array operations should be done using pointers.




1
Expert's answer
2021-11-17T17:35:27-0500
#include <iostream>
using namespace std;


void display (int array[], int size) {
    for(int i = 0; i < size; i++) {
        cout << array[i] << " ";
    }
    cout << endl;
}


int main() {
	int n;
cout<<"Enter the size of the array: ";
cin>>m;
  const int size = 5;
  int array[size] = {1, 2, 3, 4, 5};
  int temp;


  cout << "Original array: ";
  display(array, size);
  swap(array[0], array[size - 1]);
  cout << "Array after swapping largest element: ";
  display(array, size);


  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