There is such a pyramid of numbers. 
It is necessary to find all possible ways on which the sum of the numbers will be 35.45 and 55.
#define SIZE 7 int matrix [SIZE][SIZE]={ {5}, {8,7}, {9,4,4}, {6,7,5,3}, {4,8,3,7,5}, {3,9,4,9,3,8}, {5,7,9,2,4,9,3}}; void search_path(int matrix [SIZE][SIZE], int sum){ int current_sum=0,current_i=0,current_j=0, way[7]; int i,j,k=1,d; for(d=0;d<SIZE;d++){ for(i=0;i<SIZE;i++){ for(j=0;j<k;j++){ current_sum += matrix[current_i][current_j]; way[i] = matrix[current_i][current_j]; if(current_sum>sum){break;} ++current_i; ++current_j; } k++; } if(current_sum == sum && current_i == (SIZE-1) && current_j == (SIZE-1)){ print_way(way); current_i=current_j=current_sum=0; } } } I want to go through all the possible options, but somewhere the wrong algorithm did.