The problem that you described is known as partitions. It requires recurrence to get the solution. I adapted my solution from this question which contains detailed explanation of the idea. Be careful because this number grows really fast, for instance for n = 100 and k = 6 you'll get 189509 possible sums. Here's the code in C++:
#include <string>
#include <algorithm>
int nrOfSums = 0;
void partition(int n, int max, std::string prefix) {
if (n == 0) {
std::cout<<prefix<<std::endl;
nrOfSums++;
return;
}
for (int i = std::min(max, n); i >= 1; i--) {
partition(n - i, i, prefix + " " + std::to_string(i));
}
}
void partition(int n, int k) {
partition(n, k, "");
}
int main()
{
int n = 8, k = 3;
partition(n, k);
std::cout << "number of possible sums: "<< nrOfSums;
}
And the output for n = 8, k = 3:
3 3 2
3 3 1 1
3 2 2 1
3 2 1 1 1
3 1 1 1 1 1
2 2 2 2
2 2 2 1 1
2 2 1 1 1 1
2 1 1 1 1 1 1
1 1 1 1 1 1 1 1
number of possible sums: 10