Yes you are correct

Letme show u an example

Enter the elements of matrix

1 2 3 4

99

Here is your matrix:

1 2

3 4

BUT:

Enter the elements of matrix

1 2 3

99

Here is your matrix:

1 2

Printable View

- 10-03-2012kiwi101
Yes you are correct

Letme show u an example

Enter the elements of matrix

1 2 3 4

99

Here is your matrix:

1 2

3 4

BUT:

Enter the elements of matrix

1 2 3

99

Here is your matrix:

1 2 - 10-03-2012kiwi101
instead of displaying just 1 2 i want the program to say "invald # of entries" and then exit

could you please tell me how to do that? - 10-03-2012oogabooga
So you want to ensure that the user enters complete rows.

Two possibilities:

1. Check that the value of d is 0 (i.e., they entered 99 as the first value in a column).

2. Write it so entering the magic number (99) only works if it's the first value in a column.

Code:`for (c = 0; c < 10; c++)`

{

scanf("%d", &val);

if (val == 99)

break;

matrix[c][0] = val;

for (d = 1; d < m; d++) // note that d starts at 1 here

{

scanf("%d", &matrix[c][d]);

}

}

- 10-03-2012kiwi101
when I enter 1,2,3,4,99 this is what I get back from the code

Here is your matrix:

1 2

3 4

BUT

when i enter 1,2,3,99 this is what i get back

Here is your matrix:

1 2 - 10-03-2012AdakCode:
`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 to use as a break

break;

}

if (matrix[c][d] == 99)

break;

}

}

if(d<m)

printf("\nArray data is missing.\n");

- 10-03-2012kiwi101
Im so grateful to the two of you but both codes didnt work for me

The problem i have with oogaboogas code is if they enter 99 first how will the program know when the user has finished entering all entries

and the problem with adaks code is for some reason it prints the statement everytime - 10-03-2012kiwi101
Is there anyway you guys can write this statement in code and tellme where to place it it might work

Code:`if( #ofentries != c*m)`

printf("Invalid number of entries);

exit(0);

else{

print

- 10-03-2012oogabooga
How about:

Code:`if (d > 0) {`

printf("...");

exit(1);

}

- 10-03-2012Neko Tan
- 10-03-2012kiwi101
OMGSH thankyou soo muchit worked

but yeah i was just reading about fflush online too cuz mine also got stuck on the 2nd scanf - 10-03-2012kiwi101
i had one last question sorry to annoy you so much today

i want the program to exit if the user inputs a value in the matrix less than 0. i plan on writing it like

Code:`if(matrix[c][d] < 0){`

printf("not valid number");

exit(1);}

ive tired numerous times but nothing has worked out - 10-03-2012Neko TanCode:
**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] < 0){

printf ("not valid number");

getch();

exit(1);}

}

**if**(matrix[c][d] == 99)

**break**;

}

}

- 10-04-2012kiwi101
Thanks!!!! Its working!

Could you tell me why my multiplication of this matrix and its transpose is coming wrong. Its usually wrong if its not a square matrix.

Code:`for( i = 0 ; i < c ; i++ )`

{

for( d = 0 ; d < m ; d++ )

{

transpose[d][i] = matrix[i][d];

}

}

printf("Transpose of entered matrix :-\n");

for( i = 0 ; i < m ; i++ )

{

for( d = 0 ; d < c ; d++ )

{

printf("%3d\t",transpose[i][d]);

}

printf("\n");

}

// printf("The product of matrix and transpose is %d:");

for( i = 0 ; i < c ; i++ )

{

for( d = 0 ; d < m ; d++ )

{

product[i][d]=0;

for(k=0;k<c;k++) {

product[i][d] = product[i][d] + matrix[i][k] * transpose[k][d];

}

}

}

printf("\nThe Product Of The Two Matrices Is:\n\n");

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

for(d=0; d<k; d++) {

printf(" %3d ",product[i][d]);

}

printf("\n");

}

return 0;

- 10-04-2012kiwi101
The transpose is right its just the multiplication of the matrix and transpose sometimes comes wrong

- 10-04-2012kiwi101
sorry about the indentation :(