First of all, thanks for taking the time to look at my post. I'm new to C# and programming in general, so i need a little help with some homework. I have to first insert the number of rows and columns, then the elements and show the whole matrix. After that to arrange the columns in a mirror like way. For example: If the matrix has one row and 5 columns, it should look like this:
Matrix 1 2 3 4 5 should become 5 4 3 2 1
The same thing goes for more than one row.
This is what i did so far:
#include <stdio.h>
void main()
{
int m, n, i, j, matrix[10][10];
printf("Insert the number of rows and columns:\n");
scanf("%d%d", &m, &n);
printf("Insert the desired elements:\n");
for (i = 1; i <= m; i++)
for (j = 1; j <= n; j++)
scanf("%d", &matrix[i][j]);
printf("Your matrix has the following elements:\n");
for (i = 1; i <= m; i++)
{
for (j = 1 ; j <= n; j++)
{
printf("%d\t", matrix[i][j]);
}
printf("\n");
}
}
If there is a better way, or i did something wrong please tell me. As i said i'm new to programming. Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire