0
How can a user entered row of 2 by 2 or a 3 by 3 matrix can be interchanged with another row of the same matrix in c language?
Matrix is entered by the user.
9 Respostas
+ 8
Please clarify your question.
+ 8
So you want to interchange two rows of the same matrix with each other?
Can you provide the sample output to understand better?
+ 8
#include <stdio.h>
int main()
{
int rows = 3, cols = 3;
int matrix[rows][cols];
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
{
matrix[i][j] = i + j;
printf("%d ", matrix[i][j]);
}
printf("\n");
}
printf("\nInterchanging row 1 with row 2\n");
for(int i = 0; i < 1; i++)
{
for(int j = 0; j < cols; j++)
{
int temp = matrix[i][j];
matrix[i][j] = matrix[i+1][j];
matrix[i+1][j] = temp;
}
}
for(int i = 0; i < rows; i++)
{
for(int j = 0; j < cols; j++)
{
printf("%d ", matrix[i][j]);
}
printf("\n");
}
return 0;
}
+ 7
Yes you can interchange rows of two matrices in C.
+ 7
Your welcome
+ 1
Thanks man you really helped me I was working on this for 2 hours thank you very much.
0
A matrix is entered by the user it can be of 2 rows and 2 columns or 3 rows and 3 columns or 2 rows and 3 columns or 3 rows and 2 columns now user will enter the two rows number. The numbers of that two rows are to be interchanged in out put how can I write a C program for it?
0
No dude matrices are not two matrix is only one and i just only want tou interchange the value of two rows of that matrix can you plzz send me a code of c language so that I can understand it?
0
Exactly