int myArray[5]; // declare an integer array with 5 elements myArray[0] = 10; // initialize first element to value 10 myArray[1] = 20; // initialize second element to value 20 myArray[2] = 30; // initialize third element to value 30 myArray[3] = 40; // initialize fourth element to value 40 myArray[4] = 50; // initialize fifth element to value 50
int myArray[5] = {10, 20, 30, 40, 50}; // declare and initialize an integer array with 5 elements for (int i = 0; i < 5; i++) { cout << myArray[i] << " "; // print each element of the array }
#include// package library to use built-in sort() function int myArray[5] = {50, 30, 40, 20, 10}; // declare and initialize an integer array with 5 elements sort(myArray, myArray + 5); // sort the array using built-in sort() function for (int i = 0; i < 5; i++) { cout << myArray[i] << " "; // print sorted array }