ProgramsC++

Array Operations Programs

C++ array operation programs: reverse and merge arrays, merge sorted arrays, average numbers, transpose and multiply matrices, and collect factors in a vector.

7 programs · open one, then the next

Start with Reverse an Array
  1. 01Reverse an ArrayBeginnerReverse an array in C++ two ways: std::reverse from <algorithm> and a swap loop that runs only to n / 2. Traces how the ends trade places moving inward.Open example →
  2. 02Merge Two Sorted ArraysIntermediateMerge two sorted arrays into one sorted array in C++ with indexes i, j, and k. Covers the two-pointer comparison, leftover copy loops, and O(n1 + n2) cost.Open example →
  3. 03Merge Two ArraysBeginnerJoin two fixed arrays {1,2,3} and {4,5,6} end to end in C++ with two copy loops. A short drill on the n1 + i offset, with no input to get in the way.Open example →
  4. 04Average of 3 NumbersBeginnerAverage three numbers in C++ with float input and divide by 3.0, then print with two decimals. Explains why dividing by 3 with ints loses the fraction.Open example →
  5. 05Transpose of a MatrixIntermediateFind the transpose of a 3×3 matrix in C++ by copying matrix[i][j] into transpose[j][i]. Shows how rows become columns and how to handle non-square matrices.Open example →
  6. 06Matrix MultiplicationIntermediateMultiply a 2×3 matrix by a 3×2 matrix in C++ with three nested loops. Traces how 58 is computed and explains the rule that inner dimensions must match.Open example →
  7. 07Display Factors of a NumberBeginnerCollect the factors of a number into a vector in C++ and print them. Compares a vector with direct printing and shows how to cut the search to the square root.Open example →