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.

25th Nov 2018, 11:45 AM
k180226 Syed Hassan Ali
k180226 Syed Hassan Ali - avatar
9 ответов
+ 8
Please clarify your question.
25th Nov 2018, 1:07 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 8
So you want to interchange two rows of the same matrix with each other? Can you provide the sample output to understand better?
25th Nov 2018, 6:26 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 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; }
25th Nov 2018, 6:35 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 7
Yes you can interchange rows of two matrices in C.
25th Nov 2018, 1:18 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 7
Your welcome
25th Nov 2018, 6:37 PM
blACk sh4d0w
blACk sh4d0w - avatar
+ 1
Thanks man you really helped me I was working on this for 2 hours thank you very much.
25th Nov 2018, 6:37 PM
k180226 Syed Hassan Ali
k180226 Syed Hassan Ali - avatar
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?
25th Nov 2018, 1:15 PM
k180226 Syed Hassan Ali
k180226 Syed Hassan Ali - avatar
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?
25th Nov 2018, 1:21 PM
k180226 Syed Hassan Ali
k180226 Syed Hassan Ali - avatar
0
Exactly
25th Nov 2018, 6:27 PM
k180226 Syed Hassan Ali
k180226 Syed Hassan Ali - avatar