Create a basic matrix in C (input by user !)

Posted by DM on Stack Overflow See other posts from Stack Overflow or by DM
Published on 2010-05-05T20:07:15Z Indexed on 2010/05/05 20:18 UTC
Read the original article Hit count: 139

Filed under:
|

Hi there,

Im trying to ask the user to enter the number of columns and rows they want in a matrix, and then enter the values in the matrix...Im going to let them insert numbers one row at a time.

How can I create such function ?

#include<stdio.h>
main(){

int mat[10][10],i,j;

for(i=0;i<2;i++)
  for(j=0;j<2;j++){
  scanf("%d",&mat[i][j]);
  } 
for(i=0;i<2;i++)
  for(j=0;j<2;j++)
  printf("%d",mat[i][j]);

}

This works for inputting the numbers, but it displays them all in one line... The issue here is that I dont know how many columns or rows the user wants, so I cant print out %d %d %d in a matrix form ..

Any thoughts ?

Thanks :)

© Stack Overflow or respective owner

Related posts about matrix

Related posts about c