473,505 Members | 14,686 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sub matrix

36 New Member
suppose there is a matrix size colsXrows and i need to find number os sub matrices with the sum N .

this is the code for search sub matrices just on cols and rows, (sub matrices size>1)
Expand|Select|Wrap|Line Numbers
  1.            case 6:
  2.                printf("enter sum to search for ==>");
  3.                scanf("%d",&n);
  4.                for(i=0; i<cols; i++)
  5.                    for(j=0; j<rows; j++)
  6.                    {
  7.                        sum=0;
  8. //////////////////////////////////////////////////////////
  9.                        for(k=j; (k<rows)&&(sum<=n); k++)
  10.                        {
  11.                            sum=sum+arr[i][k];
  12.                        if((sum==n)&&(j<k))
  13.                          {                                    //==>  search for sub matrix sum N on rows.
  14.                            printf("#*****************#\n");
  15.                            sum=0;
  16.                          }
  17.                        }
  18.                        sum-0;
  19. //////////////////////////////////////////////////////////
  20.  
  21.                        for(k=i; (k<cols)&&(sum<=n); k++)
  22.                        {
  23.                            sum=sum+arr[k][j];
  24.                        if((sum==n)&&(i<k))
  25.                          {                                    //==>  search for sub matrix sum N on columns.
  26.                            printf("#*****************#\n");                    
  27.                            sum=0;
  28.                          }
  29.                        }
  30.                        sum=0;
  31. //////////////////////////////////////////////////////////
  32.  
in case of matrix 2X2 with the values {1,1,1,1}

for sub marices sum=2 need to get 4 sub matrices.

but something wrong in this code i gettin just 3 .
why is that ?
TNX ..........
Aug 19 '09 #1
1 5864
sedaw
36 New Member
never mind...... , find the prob on line 18 ; " sum-0 " S:
tnx anyway .
Aug 19 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
3309
by: Ben Ingram | last post by:
Hi all, I am writing a template matrix class in which the template parameters are the number of rows and number of columns. There are a number of reasons why this is an appropriate tradeoff for...
5
3785
by: Jason | last post by:
Hello. I am trying to learn how operator overloading works so I wrote a simple class to help me practice. I understand the basic opertoar overload like + - / *, but when I try to overload more...
6
6563
by: memocan | last post by:
#include <iostream> using namespace std; int x; //global variable matrix int main() { x= new float ; //initialize the size now }
14
4913
by: amitnanda | last post by:
Hi Guys, I have a matrix multiplication program in C that multiplies two matrices. When their size is 3*3 or 800*800, the program runs fine. But above that size, I get a "segmentation fault"....
20
5184
by: Frank-O | last post by:
Hi , Recently I have been commited to the task of "translating" some complex statistical algorithms from Matlab to C++. The goal is to be three times as fast as matlab ( the latest) . I've...
1
7945
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
2
8547
by: DarrenWeber | last post by:
Below is a module (matrix.py) with a class to implement some basic matrix operations on a 2D list. Some things puzzle me about the best way to do this (please don't refer to scipy, numpy and...
0
2792
by: DarrenWeber | last post by:
# Copyright (C) 2007 Darren Lee Weber # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free...
18
2445
by: Hypnotik | last post by:
Hello everyone. I'm writing a program which uses a class called matrix. I have written all of the different functions, constructor, etc. When I run the program I receive "Constructor", which I...
2
2651
by: rijaalu | last post by:
I am designing a matrix class that performs addition, multicpication, substraction and division. When ever i complie the code it shows an error. include <iostream> using namespace std; class...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7303
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5613
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5028
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1528
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
407
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.