Answer the question
In order to leave comments, you need to log in
How to construct another matrix from a given matrix using a formula?
Text of the problem:
Let the matrix A be given, dimension nx n. It is necessary to build a matrix B, and the elements of the matrix are built according to the following formula where the area is indicated in the figure (attached)
My code:
int main()
{
const int n=8;
int a[n][n], b[n][n], l=0;
for(int i=0; i<n; i++)
{
a[i][i]=i;
b[i][i]=0;
}
b[0][0] = a[0][0];
for(int i=0; i<n; i++)
{
for(int j=1; j<n; j++)
{
int min = a[0][0];
for(int s=i; s<n; s++)
{
l=n/4;
for(int d=j; d<n && n-l!=0; d++)
{
if(d<=n/2 && s<=n-l)
{
if(a[s][d] < min)
min=a[s][d];
}
}
l++;
}
b[i][j]=min;
}
}
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
cout<<b[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
Answer the question
In order to leave comments, you need to log in
for(int i=0; i<n; i++)
{
a[i][i]=i;
b[i][i]=0;
}
for(int i=0; i<n; i++)
{
for(int j=0; j<n; j++)
{
cout<<b[i][j]<<" ";
}
cout<<endl;
}
for(int i=0; i<n; i++){
for(int j=0; j<n; j++){
a[i][j]=rand();
b[i][j]=-1;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question