64 763
Assignments Done
99,3%
Successfully Done
In September 2018

Answer to Question #59317 in C for grey john

Question #59317
how can I delete a row and column from a matrix?
Expert's answer
#include <stdio.h>
#define DELETED_ROW 0
#define DELETED_COLUMN 0

int main(int argc, char *argv[])
{
int A[3][3], B[2][2];
int i, j;
for (i = 0; i < 3; i++)
for (j = 0; j < 3; j++)
A[i][j] = i * 3 + j + 1;
for (i = 0; i < 3; i++)
{
printf("\n");
for (j = 0; j < 3; j++)
printf("A[%d][%d]=%d\t", i, j, A[i][j]);
}
for (i = 0; i < 3; i++)
if (i != DELETED_ROW)
{
for (j = 0; j < 3; j++)
if (j != DELETED_COLUMN)
{
if (i < DELETED_ROW && j < DELETED_COLUMN)
B[i][j] = A[i][j];
else if (i < DELETED_ROW && j > DELETED_COLUMN)
B[i][j-1] = A[i][j];
else if (i > DELETED_ROW && j < DELETED_COLUMN)
B[i-1][j]=A[i][j];
else
B[i-1][j-1]=A[i][j];
}
}
for (i = 0; i < 2; i++)
{
printf("\n");
for (j = 0; j < 2; j++)
printf("B[%d][%d]=%d\t", i, j, B[i][j]);
}
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions