Subarray sum problem

Print all possible subarray that is equal to target sum ex 1,2,3,4,5 6 output 1,2,3
6
4,5
5,1
2 4
Solve in c++ and do not use vector
Also count how many subarrays there are