# short matrix problem

Show 80 post(s) from this thread on one page
Page 4 of 6 First 123456 Last
• 10-04-2012
Salem
And don't play the "I don't have time" game either.
I've just done the renaming in your code, and it took exactly 5 minutes to do - including retesting.

Code:

```\$ ./a.out Enter the number of columns of matrix 5 Enter the elements of matrix 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 99 Here is your matrix:   1  2  3  4  5   6  7  8  9  10  11  12  13  14  15 Transpose of entered matrix :-   1          6        11          2          7        12          3          8        13          4          9        14          5        10        15        The Product Of The Two Matrices Is:   55  130  205  130  330  530  205  530  855```
• 10-04-2012
kiwi101
when i did that i get
55
130
205
0
0
130
330
530
0
0
205
530
855
0
0
• 10-04-2012
kiwi101
when i did what salem told me i get
55
130
205
0
0
130
330
530
0
0
205
530
855
0
0
• 10-04-2012
kiwi101
SORRY FOR MY DUMBNESS!!!
I got it THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
• 10-04-2012
kiwi101
another question for u guys if instead of 99 is there another way my program can detect that the user is done typing?? what if i do EOF?
Code:

```#include<stdio.h> #include<stdlib.h> int  main() {   int val, m,x, n, c = 0, d,k, matrix[10][10], transpose[10][10], product[10][10]; //defining variables   printf("Enter the number of columns of matrix ");   scanf("%d",&m);   if(m<=0){  //error checking if user enter negative number or 0 for column     printf("You entered a invalid value.\n");     exit(0);   }   else{     printf("Enter the elements of matrix \n");     for( c = 0 ; c < 10 ; c++) //forst for loop to scan the matrix       {         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;             if (matrix[c][d] < 0){ //error checking if any entries in the matrix are negative               printf ("you entered an invalid number\n");               exit(1);}           }         if (matrix[c][d] == 99)           break;           }   }   if (d > 0){ //error checking to make sure the number of entries is correct     printf("The number of entries is not valid\n");     exit(1);   }   printf("\nHere is your matrix:\n");   int i; //declaring i to be count for row   for(i=0;i<c;i++)     {       for(d=0;d<m;d++)         {           printf("%3d ",matrix[i][d]);         }       printf("\n");     }```
• 10-04-2012
kiwi101
last question please give some ideas!!
• 10-04-2012
Salem

I was going to say something, but now I'll leave it to the next person to have a go instead.
How To Ask Questions The Smart Way
• 10-04-2012
EOF is a multi-key entry, that most users won't know how to enter.

You could take user entry as a string, and convert it with sscanf(). Then it's simple to stop by entering a letter.
• 10-04-2012
kiwi101
if I use EOF instead of 99 it only works with input files not if the user directly enters it
• 10-04-2012
christop
Quote:

Originally Posted by kiwi101
if I use EOF instead of 99 it only works with input files not if the user directly enters it

It works perfectly fine with direct user input by typing Ctrl-D (every OS except for DOS/Windows) or Ctrl-Z and enter (only DOS/Windows). Adak is right, though. It's a multi-key input (3 keys for DOS/Windows or 2 for every other OS).
• 10-04-2012
laserlight
Quote:

Originally Posted by kiwi101
if I use EOF instead of 99 it only works with input files not if the user directly enters it

That's probably because you're one of the users who doesn't know how to trigger the end of file condition when entering input :)

Try entering CTRL + D or CTRL + Z on a separate line.
• 10-04-2012
kiwi101
At Salem I won't say anything to you cuz you helped me thanks :)
and Adak thanks i know thatll get me started
if I wanted the program to exit if the user has more than 10 rows or 10 columns how would I go about writing that?
• 10-04-2012
kiwi101
thanks i didnt know how to trigger the EOF
• 10-04-2012
kiwi101
if I wanted the program to exit if the user has more than 10 rows or 10 columns how would I go about writing that?
• 10-04-2012
kiwi101
i know how to do 10 columns but rows i guess has some trick
Show 80 post(s) from this thread on one page
Page 4 of 6 First 123456 Last