matrix challenge

Discussion in 'C' started by chai123, Oct 4, 2012.

1. chai123New Member

Joined:
Oct 4, 2012
Messages:
1
0
Trophy Points:
0
Okay so Ive made a program that only asks a user for the # of columns of a matrix and then determines the rows of the matrix and displays it. The problem is if the user for example for a 2 by 2 matrix enters only 3 values then the program doesnt work. I want the program to show 2 rows for 3 values and then maybe put 0 as the fourth value. Please help
Code:
```#include<stdio.h>
#include<stdlib.h>

int  main()
{
int m,x, n, c = 0, d,k, matrix[10][10], transpose[10][10], product[10][10];

printf("Enter the number of columns of matrix ");
scanf("%d",&m);
if(m<=0){
printf("You entered a invalid value.");
exit(0);
}
else{
printf("Enter the elements of matrix \n");

for( c = 0 ; c < 10 ; c++ )
{
for( d = 0 ; d < m ; d++ )
{
scanf("%d",&matrix[c][d]);
if (matrix[c][d] == 99) // 'x' is character variable I declared to use as a break
break;
// c = c+1;

}
if (matrix[c][d] == 99)
break;
}
}

int i;

for(i=0;i<c;i++)
{
for(d=0;d<m;d++)
{
/* if( matrix[c][d] <0){
printf("Not possible");
exit(0);
}
else{*/

printf("%3d ",matrix[i][d]);
}
printf("\n");
}```