whats wrong with by sudoku code I have used backtracking
but I am getting a segmentation fault
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll t,n,mat[10][10],possible[10],xe,ye;
bool is_full(ll mat[10][10])
{
//check if any cell is empty
for(ll i=1;i<=9;i++)
{
for(ll j=1;j<=9;j++)
{
if(mat[i][j]==0)
{
return false;
}
}
}
return true;
}
bool prow(ll mat[10][10], ll row , ll col ,ll num)
{
//checking in the same row
for(ll j=1;j<=9;j++)
{
if(mat[row][j]==num)
{
return true;
}
}
return false;
}
bool pcol(ll mat[10][10],ll row,ll col ,ll num)
{
//checking in the same column
for(ll i=1;i<=9;i++)
{
if(mat[i][col]==num)
{
return true;
}
}
return false;
}
bool box(ll mat[10][10],ll row,ll col ,ll num)
{
//checking in the same 3*3 matrix
row--;
col--;
row=(row-row%3)+1;
col=(col-col%3)+1;
for(ll i=row;i<=row+2;i++)
{
for(ll j=col;j<=col+2;j++)
{
if(mat[i][j]==num)
{
return true;
}
}
}
return false;
}
bool is_safe(ll mat[10][10] , ll row , ll col , ll num)
{
if(mat[row][col]==0 && !prow(mat,row,col,num) && !pcol(mat,row,col,num) && !box(mat,row,col,num))
{
return true;
}
else
{
return false;
}
}
void print(ll mat[10][10])
{
for(ll i=1;i<=9;i++)
{
for(ll j=1;j<=9;j++)
{
cout<<mat[i][j]<<" ";
}
cout<<endl;
}
}
bool solve(ll mat[10][10])
{
//base condition : every cell is filled
if(is_full(mat))
{
return true;
}
//finding the first empty cell
for(ll i=1;i<=9;i++)
{
for(ll j=1;j<=9;j++)
{
if(mat[i][j]==0)
{
xe=i;
ye=j;
break;
}
}
}
//check each number in possible array
for(ll i=1;i<=9;i++)
{
if(is_safe(mat,xe,ye,i))
{
mat[xe][ye]=i;
}
//try to solve
//using the current
//assignment of num
if(solve(mat))
{
return true;
}
//if it is not solvable
//try new configuration
//backtrack
mat[xe][ye]=0;
}
//after trying every
//possible configuration
//if it fails return false
//trigger backtracking
return false;
}
int main()
{
cin>>t;
while(t--)
{
for(ll i=1;i<=9;i++)
{
for(ll j=1;j<=9;j++)
{
cin>>mat[i][j];
}
}
if(solve(mat))
{
print(mat);
}
else
{
cout<<-1<<endl;
}
}
return 0;
}