void recursion(int k,int n,int* returnSize,int* ColSize,int start,int cnt,int sum,int* temp,int** arr){ if(cnt==k){ if(sum==n){ arr[(*returnSize)]=(int*)calloc(cnt,sizeof(int)); memcpy(arr[(*returnSize)],temp,sizeof(int)*cnt); ColSize[(*returnSize)++]=cnt; } return; } for (int i=start; i<=9 && sum<n; i++) { temp[cnt]=i; recursion(k,n,returnSize,ColSize,i+1,cnt+1,sum+i,temp,arr); } } int** combinationSum3(int k, int n, int* returnSize, int** returnColumnSizes){ int** arr=(int**)calloc(1000,sizeof(int*)); int temp[1000]; *returnSize=0; *returnColumnSizes=(int*)calloc(1000,sizeof(int)); recursion(k,n,returnSize,*returnColumnSizes,1,0,0,temp,arr); return arr; }