1. ## short matrix problem

In this program I only input the number of columns and the entries of the matrix. The program then determines the number of rows. The program works perfectly for the correct number of entries like 4 entries for a 2 by 2 matrix. However it doesnt work for 3 entries for a 2 by 2 matrix. Please reply fast
Code:

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) // 99 is  variable I declared to use as a break
break;

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

int i;

for(i=0;i<c;i++)
{
for(d=0;d<m;d++)
{

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

2. Originally Posted by kiwi101
fast

(If I wanted to be nasty, I would have let my reply stop here, but I'll be kind. Next time, don't insist that people "reply fast".)

Originally Posted by kiwi101
However it doesnt work for 3 entries for a 2 by 2 matrix.
How does it not work? Also, you should indent your code properly to make it easier to read.

3. Do you want an m x m, or a 10 x m matrix?

4. u miss fflush()... u need to clear ur buffer rite after input from user else ur next scanf will still take ur previous entered number as input(in the case that next scanf very close together)

question for u: are u on a open book test or something?

5. sorry
i was just getting tensed since ive bin working on this for ages and i cant get any ideas

it does work if i put 3 entries but not the way it shoud like itll give me garbage values.

6. no im not i just have this due in a couple of hours.

Could u elaborate? ive neve rused fflush

7. Okay I have an idea I just dont know how to quite put it down. If the user doesnt enter m*n entries then the program should just exit
kindof like this
Code:
``` if(m*c%m != 0){
printf("NO");
exit(0);
}
else{
print```

8. Why haven't you answered laserlight's or TheBigH's questions?

Neko Tan doesn't know what it's talking about. fflush is not needed.

Indent your code properly. Look at post #7. Is that really how you mean your code to look?

9. I did reply to laserlight.
Look im just trying to brainstorm i want the matrix to be a m*n matrix.
i want my code to exit if the user doesnt enter m*n values.
Could you please give me some direction?
Im waitng here

10. If it's supposed to be m x n why don't you set n to anything? You're not even using it.

11. m = # of rows
in this program my # of rows is called c

n= # of columns
in this program my # of colums is called m

so a c*m matrix

12. Could you guys please not make fun of me and help me plz

13. Yes, I see your stressed out, so I deleted my funny post.

Quickly, what's the problem?

14. Your variable names are terrible. Why is n called m and m called c???

Anyway, I think I'm beginning to understand what you're up to here. You want the user to enter the number of columns (but NOT the number of rows). Then the user inputs rows of data until they decide to stop by entering the number 99.

Is that correct?

Can you show an exact example of what doesn't work?

15. Thanks
let me explain it with an example please tell me if you get it
when the user enters 2 as the # of columns. And then enter 1,2,3,4 as the input. The program automatically displays a 2 by 2 matrix with 1,2,3,4 entries. However my problem is that if that same user accidentally only entered 1,2,3 then I want the program to exit using the exit function. But I don't know how to write it properly could you please tell me how i should write it.