Thread: how to find a sub matrix..

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    how to find a sub matrix..

    when i enter a number and it needs to show
    how many sub matrices that the sum of there members equals the number which i entered

    how to do that
    ??

  2. #2
    Registered User drdebcol's Avatar
    Join Date
    Dec 2008
    Location
    Kernel Memory
    Posts
    1
    I don't know if this is what you think, but i found a solution ! You have to enter that
    number or "addition" and them enter length and height of matrix and max-length
    and max-height of sub-matrix and then whole matrix ! After that you will get solution
    or better said number of sub-matrix !
    Code:
    #include <iostream>
    #include <math.h>
    
    using namespace std;
    int main()
    {
       cout<<"- - - - - - - - - - - - - - - - - - -\n";
       cout<<" Program for finding sub matrix with\n";
       cout<<"   entered addition by Dr DEBCOL !\n";
       cout<<"- - - - - - - - - - - - - - - - - - -\n";
       int i,j,n,f,t,r,e;
       cout<<"Enter addition !\n";
       cin>>t;  //ADDITION
       cout<<"Enter length of matrix ?\n";
       cin>>n; //N IS LENGTH
       cout<<"Enter height of matrix ?\n";
       cin>>f;  //F IS HEIGHT
       cout<<"Enter maximum length of sub-matrix ?\n";
       cin>>r; //R IS LENGTH OF SUB-MATRIX
       cout<<"Enter maximum height of sub-matrix ?\n";
       cin>>e;  //E IS HEIGHT OF SUB-MATRIX
       cout<<"Enter array with parts separated with space !\n";
       cout<<"After you finish one line press Enter to type another !\n";
    
         int a[n][f];
          for (i=1;i<=n;i++)
          for (j=1;j<=f;j++)
           cin>>a[i][j];
           
        int i1,j1,i2,j2,s,k;
         s=0;
         k=0;
        for (i1=1;i1<=n;i1++)
        for (j1=1;j1<=f;j1++)
        { 
          s=0;
        for (i2=i1;i2<=(r+i1);i2++)
        for (j2=j1;j2<=(e+j1);j2++) 
        {
           s+=a[i2][j2];
           if (s==t) 
           {
           k++;
           s=0;
           }
           }
        }
        cout<<"Number of sub matrix with "<<t<<" addition is "<<k<<" ! \n";
         cin.get(); 
         cin.get();
    }
    Visit this programming forum : http://www.syntax-e.co.cc/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting orientation and position in opengl
    By ting in forum Game Programming
    Replies: 9
    Last Post: 07-07-2008, 04:13 PM
  2. Music Programming - Serial Matrix Display (Help needed)
    By CrazyHorse in forum C Programming
    Replies: 1
    Last Post: 11-13-2007, 04:28 PM
  3. Music Programming - Serial Matrix Display
    By CrazyHorse in forum C Programming
    Replies: 1
    Last Post: 11-12-2007, 04:16 PM
  4. working with rotation matrices
    By hannibar in forum Game Programming
    Replies: 23
    Last Post: 03-30-2005, 01:10 PM
  5. Matrix Reloaded Questions (SPOILERS_
    By Xei in forum A Brief History of Cprogramming.com
    Replies: 73
    Last Post: 10-19-2003, 02:21 PM