Matrix column mirror like rearrange in C [SOLVED] -
i have first insert number of rows , columns, elements , show whole matrix. after arrange columns in mirror way. example: if matrix has 1 row , 5 columns, should this:
matrix 1 2 3 4 5 should become 5 4 3 2 1
the same thing goes more 1 row.
this did far:
#include <stdio.h> void main() { int m, n, i, j, matrix[10][10]; printf("insert number of rows , columns:\n"); scanf("%d%d", &m, &n); printf("insert desired elements:\n"); (i = 0; < m; i++) (j = 0; j < n; j++) scanf("%d", &matrix[i][j]); printf("your matrix has following elements:\n"); (i = 0; < m; i++) { (j = 0 ; j < n; j++) { printf("%d\t", matrix[i][j]); } printf("\n"); } }
if there better way, or did wrong, please tell me.
solved added following:
printf("your new matrix has following elements:\n"); (i = m-1; >= 0; i--) { (j = n-1 ; j >= 0; j--) { printf("%d\t", matrix[i][j]); } printf("\n"); }
thanks jonathan leffler idea.
transferring comment answer.
you've got moderately start; need show code print data in reverse order — presumably counting down instead of counting up, @ least in inner loop , possibly in both loops.
your data entry code should check scanf()
succeeds each time, , should check neither m
nor n
bigger 10 (or less 1, less dangerous; won't in relevant loop).
bug: counting 1..m , 1..n, in c, array indexes go 0..m-1 , 0..n-1.
Comments
Post a Comment