Obligatory solution using C++20 ranges:
#include <algorithm>#include <iostream>#include <ranges>int main(){ int arr[] = {7,8,6,4,5,1,4,3,5}; int n = 3; for (auto &&segment : arr | std::views::chunk(n)) std::ranges::sort(segment); for (int x : arr) std::cout << x << ''; std::cout << '\n';}
But since you're probably asked to implement this manually: Make a sorting function (using whatever algorithm you want) that just sorts an entire array. It will probably accept a pointer and a length as parameters (or two pointers). You can then apply it to individual subarrays in a loop.