Like Tree4Likes

short matrix problem

This is a discussion on short matrix problem within the C Programming forums, part of the General Programming Boards category; And don't play the "I don't have time" game either. I've just done the renaming in your code, and it ...

  1. #46
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    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
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  2. #47
    Registered User
    Join Date
    May 2012
    Posts
    210
    when i did that i get
    55
    130
    205
    0
    0
    130
    330
    530
    0
    0
    205
    530
    855
    0
    0

  3. #48
    Registered User
    Join Date
    May 2012
    Posts
    210
    when i did what salem told me i get
    55
    130
    205
    0
    0
    130
    330
    530
    0
    0
    205
    530
    855
    0
    0

  4. #49
    Registered User
    Join Date
    May 2012
    Posts
    210
    SORRY FOR MY DUMBNESS!!!
    I got it THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

  5. #50
    Registered User
    Join Date
    May 2012
    Posts
    210
    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");
        }

  6. #51
    Registered User
    Join Date
    May 2012
    Posts
    210
    last question please give some ideas!!

  7. #52
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,845
    Seriously - stop bumping your own threads every couple of minutes with some pithy "please help".

    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
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #53
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    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.

  9. #54
    Registered User
    Join Date
    May 2012
    Posts
    210
    if I use EOF instead of 99 it only works with input files not if the user directly enters it

  10. #55
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    383
    Quote Originally Posted by kiwi101 View Post
    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).

  11. #56
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,302
    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.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  12. #57
    Registered User
    Join Date
    May 2012
    Posts
    210
    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?

  13. #58
    Registered User
    Join Date
    May 2012
    Posts
    210
    thanks i didnt know how to trigger the EOF

  14. #59
    Registered User
    Join Date
    May 2012
    Posts
    210
    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?

  15. #60
    Registered User
    Join Date
    May 2012
    Posts
    210
    i know how to do 10 columns but rows i guess has some trick

Page 4 of 6 FirstFirst 123456 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 10-01-2012, 11:57 PM
  2. How come short + int = int but short + uint = long?
    By y99q in forum C# Programming
    Replies: 2
    Last Post: 10-29-2011, 12:16 PM
  3. Please help! short while loop tracking problem.
    By matthayzon89 in forum C Programming
    Replies: 7
    Last Post: 04-22-2010, 01:29 PM
  4. Replies: 2
    Last Post: 04-21-2008, 08:43 PM
  5. Replies: 7
    Last Post: 02-08-2008, 06:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21