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.
#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;
}
Comments
Leave a comment