I am trying to compute the largest of the sums of numbers that appear on the paths of a triangle of numbers starting from the top towards the base so that on each path the next number is located on the row below, more precisely either directly below or below and one place to the right. Getting a Segmentation fault. Don't know why??
#include<stdio.h>
#include<stdlib.h>
int func(int **arr, int n, int i,int max)
{
int j,m,a,b,c;
if(i==(n-1))
return max;
else
{
for(j=0;j<=i;j++)
{
a=*(*(arr+i)+j);
b=*(*(arr+(i+1))+j);
c=*(*(arr+(i+1))+(j+1));
if(((a+b)>=(a+c))&&((a+b)>max))
{
max=(a+b);
m=j;
}
if(((a+c)>(a+b))&&((a+c)>max))
{
max=(a+c);
m=j+1;
}
}
*(*(arr+(i+1))+m)=max;
func(arr,n,i+1,max);
}
}
int main()
{
int n,array[100][100],i,j;
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
scanf("%d",&array[i][j]);
}
printf("%d\n",func(array,n,0,0));
return 0;
}