Thread: simple matrix

  1. #61
    Registered User
    Join Date
    Nov 2012
    Posts
    106
    Thanks its working
    Code:
    #include<stdio.h>
    #include <stdlib.h>
    
    int main (void)
    {
      int row_size1,col_size1,row_size2,col_size2,flag =1;
      int **A;
      int i = 0, j = 0;
      char a,c;
    
    do
      {
        printf("\ncmd> ");
        c = getchar();
    
    if(c == 'A')
          {
    
    scanf("%d %d",&row_size1,&col_size1);
    
    A= malloc(row_size1*sizeof(int*));
      for(i=0;i<row_size1;i++)
        {
          A[i]=malloc(col_size1*sizeof(int));
        }
    
    for(i=0;i<row_size1;i++)
        {
         for(j=0;j<col_size1;j++)
            {
              scanf("%d",&A[i][j]);
              if (A[i][j] == 99) // 'x' is character variable i declared
                break;
            }
        }
    
    printf("The required matrix is\n");
      for(i=0;i<row_size1;i++)
        {
          for(j=0;j<col_size1;j++)
          printf("%d ",A[i][j]);
          printf("\n");
        }
      
    
    for(i=0;i<row_size1;i++)
        {
    free(A[i]);
        }
      free(A);
          }
      }
     while(flag == 1);
     return 0;
    }
    Last edited by zafy; 11-14-2012 at 11:23 PM.

  2. #62
    Registered User
    Join Date
    Nov 2012
    Posts
    106
    let me fix indentation

  3. #63
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    And the crowd goes wild!
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help in Matrix Addition & finding Inverse of a Matrix
    By ssatyan.129 in forum C Programming
    Replies: 6
    Last Post: 05-15-2009, 02:48 PM
  2. help with simple programs. Matrix multiplications
    By ovadoggvo in forum C Programming
    Replies: 1
    Last Post: 05-18-2005, 11:46 PM
  3. Matrix Multiplication with simple syntax! plz help.
    By codebox in forum C Programming
    Replies: 6
    Last Post: 11-05-2004, 09:03 AM
  4. Simple Matrix Operations?
    By devin in forum C++ Programming
    Replies: 4
    Last Post: 12-15-2003, 12:10 AM
  5. Matrix: Reloaded + Enter The Matrix (the game)
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 04-18-2003, 12:35 AM