to convert this code to Ocaml programming language? void flip_matrix(bool arr[n][m],int x,int y) { for(int i=0;i
How to convert this code to Ocaml
void flip_matrix(bool arr[n][m],int x,int y)
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(i==x && j==y)
{
arr[i][j]=!arr[i][j];
if(i+1<n ) // down element
{
arr[i+1][j]=!arr[i+1][j];
}
if(j+1<m) // right element
{
arr[i][j+1]=!arr[i][j+1];
}
if(j-1>=0) //// left element
{
arr[i][j-1]=!arr[i][j-1];
}
if(i-1>=0) // up element
{
arr[i-1][j]=!arr[i-1][j];
}
}
}
}
}
2)
void print_matrix(bool arr[n][m])
{
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
if(arr[i][j]==true)
{
cout<<"T"<<" ";
}
else
{
cout<<"F"<<" ";
}
}
cout<<"\n";
}
}
Step by step
Solved in 2 steps