Need Help Plzzz..How do I split a 2D array?
I have a 2 dimensional array with integers in it..I need to split the 2 dimensional array into parts and add all values in each part.This is how it works.When i give a number 'n' as input it should divide the array into 'n^2' equal parts.
For ex:if i have a 6x6 array & when i give an input as 3 it should split the array into 9 equal parts i:e each array should be of size 2x2.
For the same 6x6 array if i give an input as 2 then it should divide the array into 4 equal parts i:e each array should be of size 3x3.I need this to be done only for even numbered perfect square arrays i:e2x2,4x4,6x6 etc...hope u understood.Can somebody help me on this ASAP.
[682 byte] By [
murua] at [2007-11-27 10:38:45]

What have you tried?
What are you having trouble with?
EDIT: Nevermind. Since you said ASAP, I'm no longer interested.
Message was edited by:
jverd
jverda at 2007-7-28 18:56:26 >

I hav no idea how to go about doing this!!!Actually i've got to do the same operations in 3D arrays.I'm first tryin it with 2D arrays before switching to 3D..
murua at 2007-7-28 18:56:26 >

muru, you are new here, so I will try to be gentle. Please understand that when you say ASAP or urgent you are apt to make many members here angry. The thinking is, why should your problem be any more important than anyone elses? .... and ... your urgency is not our urgency. ... and ... just because you may have waited til last minute, what gives you the right to tell me to drop everything and attend to your problem?
Realize that all of us here are volunteers, that we help because we like to help. In my experience, if someone posts a problem and shows that they have put thought both in formulating their question and in trying to find their own solution, they will often get useful and prompt help.
Hope this information helps you in your next attempts at posting here.
Good luck.
Ohkk..I'm really sorry and thanx.I'll make sure this does not happen in the future.Actually i'm able to do this only for a single input.This is wat i've done so far
import java.io.*;
import java.lang.*;
import java.util.*;
public class fileinput
{
public static int [][] values;
public static int [][] values1;
public static int [][] newdc;
public static int [][] newdc1;
public static int nr1,nc1;
public static void main(String [] args)
{
int count;
int root1=0;
//int nr1,nc1;
try
{
FileReader fr=new FileReader("C:/thesis/data.txt");
BufferedReader br=new BufferedReader(fr);
String line=br.readLine();
StringTokenizer st=new StringTokenizer(line);
count=st.countTokens();
Double root=Math.sqrt(count);
root1=root.intValue();
values = new int[root1][root1];
values1 = new int[root1][root1];
while ( st.hasMoreTokens() )
{
for(int r=0;r<root1;r++)
for(int c=0;c<root1;c++)
{
values[r][c]=Integer.parseInt(st.nextToken());
}
}
}
catch(FileNotFoundException e)
{
System.out.println("file not found");
}
catch(IOException e)
{
System.out.println("error");
}
System.out.println("DATA CUBE");
for(int i=1;i<root1+1;i++)
System.out.print("" + i);
System.out.println();
for(int r=0;r<root1;r++)
{
System.out.print((r+1) + "");
for(int c=0;c<root1;c++)
System.out.print(values[r][c] + "");
System.out.println();
}
// CREATING PREFIX CUBE
for(int r1=0;r1<root1;r1++)
for(int c1=0;c1<root1;c1++)
{
int vv = getvalue(r1,c1);
values1[r1][c1] = vv;
}
System.out.println("PREFIX CUBE");
for(int i=1;i<root1+1;i++)
System.out.print("" + i);
System.out.println();
for(int r1=0;r1<root1;r1++)
{
System.out.print((r1+1) + "");
for(int c1=0;c1<root1;c1++)
System.out.print(values1[r1][c1] + "");
System.out.println();
}
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the 'x' dimension sequence:");
int xbs = Integer.parseInt(in.readLine());
System.out.println("enter the 'y' dimension sequence:");
int ybs = Integer.parseInt(in.readLine());
System.out.println(xbs);
System.out.println(ybs);
nr1=root1/xbs;
nc1=root1/xbs;
newdc = new int[root1][root1];
//newdc1 = new int[nr1][nc1];
for(int i=0;i<nr1;i++)
for(int j=0;j<nc1;j++)
{
int vv = getvalue(i,j);
newdc[j]=vv;
}
for (int i=nr1;i<root1;i++)
for(int j=0;j<nc1;j++)
{
int vv = getvalue2(i,j);
newdc[j] = vv;
}
for (int i=0;i<nr1;i++)
for (int j=nc1;j<root1;j++)
{
int vv = getvalue3(i,j);
newdc[j] = vv;
}
for (int i=nr1;i<root1;i++)
for (int j=nc1;j<root1;j++)
{
int vv = getvalue4(i,j);
newdc[j] = vv;
}
System.out.println("New Data Cube");
for(int i=1;i<root1;i++)
System.out.print("" + i);
System.out.println();
System.out.println("--");
for(int i=0;i<root1;i++)
{
System.out.print((i+1) + "|" + "");
for(int j=0;j<root1;j++)
System.out.print(newdc[j] + "");
System.out.println();
}
}
catch(IOException e)
{
}
}
public static int getvalue(int i,int j)
{
int valuestemp=0;
for(int a=i;a>=0;a--)
for(int b=j;b>=0;b--)
{
valuestemp = valuestemp + values[a];
}
return valuestemp;
}
public static int getvalue2(int i,int j)
{
int valuestemp=0;
for(int a=i;a>=nr1;a--)
for(int b=j;b>=0;b--)
{
valuestemp = valuestemp + values[a];
}
return valuestemp;
}
public static int getvalue3(int i,int j)
{
int valuestemp=0;
for(int a=i;a>=0;a--)
for(int b=j;b>=nc1;b--)
{
valuestemp = valuestemp + values[a];
}
return valuestemp;
}
public static int getvalue4(int i,int j)
{
int valuestemp=0;
for(int a=i;a>=nr1;a--)
for(int b=j;b>=nc1;b--)
{
valuestemp = valuestemp + values[a];
}
return valuestemp;
}
}
murua at 2007-7-28 18:56:26 >

You need to use code tags for two reasons:
1) It makes your code readable, and thus more likely to be read, and
2) It will prevent your [ b] indexes from disappearing and turning your text bold.
You can find out about them here:
http://forum.java.sun.com/help.jspa?sec=formatting
This works only for the input 2.I'm not sure how I go about in generalizing the code so that it works for all inputs.
murua at 2007-7-28 18:56:26 >

I've always wondered...
Do people even read their own posts after they submit them? Do they not see how unreadable the code is? Do they not notice it suddenly switching to italics (and in this case, bold)? Do they not stop to consider why it does that and if there's a way to make it not do that? This lack of ability or even interest in debugging their posts doesn't bode well for their ability to produce working code.
jverda at 2007-7-28 18:56:26 >

import java.io.*;
import java.lang.*;
import java.util.*;
public class fileinput
{
public static int [][] values;
public static int [][] values1;
public static int [][] newdc;
public static int [][] newdc1;
public static int nr1,nc1;
public static void main(String [] args)
{
int count;
int root1=0;
//int nr1,nc1;
try
{
FileReader fr=new FileReader("C:/thesis/data.txt");
BufferedReader br=new BufferedReader(fr);
String line=br.readLine();
StringTokenizer st=new StringTokenizer(line);
count=st.countTokens();
Double root=Math.sqrt(count);
root1=root.intValue();
values = new int[root1][root1];
values1 = new int[root1][root1];
while ( st.hasMoreTokens() )
{
for(int r=0;r<root1;r++)
for(int c=0;c<root1;c++)
{
values[r][c]=Integer.parseInt(st.nextToken());
}
}
}
catch(FileNotFoundException e)
{
System.out.println("file not found");
}
catch(IOException e)
{
System.out.println("error");
}
System.out.println("DATA CUBE");
for(int i=1;i<root1+1;i++)
System.out.print(" " + i);
System.out.println();
for(int r=0;r<root1;r++)
{
System.out.print((r+1) + " ");
for(int c=0;c<root1;c++)
System.out.print(values[r][c] + " ");
System.out.println();
}
// CREATING PREFIX CUBE
for(int r1=0;r1<root1;r1++)
for(int c1=0;c1<root1;c1++)
{
int vv = getvalue(r1,c1);
values1[r1][c1] = vv;
}
System.out.println("PREFIX CUBE");
for(int i=1;i<root1+1;i++)
System.out.print(" " + i);
System.out.println();
for(int r1=0;r1<root1;r1++)
{
System.out.print((r1+1) + " ");
for(int c1=0;c1<root1;c1++)
System.out.print(values1[r1][c1] + " ");
System.out.println();
}
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the 'x' dimension sequence:");
int xbs = Integer.parseInt(in.readLine());
System.out.println("enter the 'y' dimension sequence:");
int ybs = Integer.parseInt(in.readLine());
System.out.println(xbs);
System.out.println(ybs);
nr1=root1/xbs;
nc1=root1/xbs;
newdc = new int[root1][root1];
//newdc1 = new int[nr1][nc1];
for(int i=0;i<nr1;i++)
for(int j=0;j<nc1;j++)
{
int vv = getvalue(i,j);
newdc[j]=vv;
}
for (int i=nr1;i<root1;i++)
for(int j=0;j<nc1;j++)
{
int vv = getvalue2(i,j);
newdc[j] = vv;
}
for (int i=0;i<nr1;i++)
for (int j=nc1;j<root1;j++)
{
int vv = getvalue3(i,j);
newdc[j] = vv;
}
for (int i=nr1;i<root1;i++)
for (int j=nc1;j<root1;j++)
{
int vv = getvalue4(i,j);
newdc[j] = vv;
}
System.out.println("New Data Cube");
for(int i=1;i<root1;i++)
System.out.print(" " + i);
System.out.println();
System.out.println("--");
for(int i=0;i<root1;i++)
{
System.out.print((i+1) + "|" + " ");
for(int j=0;j<root1;j++)
System.out.print(newdc[j] + " ");
System.out.println();
}
}
catch(IOException e)
{
}
}
public static int getvalue(int i,int j)
{
int valuestemp=0;
for(int a=i;a>=0;a--)
for(int b=j;b>=0;b--)
{
valuestemp = valuestemp + values[a];
}
return valuestemp;
}
public static int getvalue2(int i,int j)
{
int valuestemp=0;
for(int a=i;a>=nr1;a--)
for(int b=j;b>=0;b--)
{
valuestemp = valuestemp + values[a];
}
return valuestemp;
}
public static int getvalue3(int i,int j)
{
int valuestemp=0;
for(int a=i;a>=0;a--)
for(int b=j;b>=nc1;b--)
{
valuestemp = valuestemp + values[a];
}
return valuestemp;
}
public static int getvalue4(int i,int j)
{
int valuestemp=0;
for(int a=i;a>=nr1;a--)
for(int b=j;b>=nc1;b--)
{
valuestemp = valuestemp + values[a];
}
return valuestemp;
}
}
murua at 2007-7-28 18:56:26 >

> I've always wondered...
>
> .......................
> .......................
> This lack of ability or even interest in
> debugging their posts doesn't bode well for their
> ability to produce working code.
It's his first foray into this forum. I can remember (not very long ago) being this ignorant or worse.
I'm really sorry for not following the guidelines.I'm learning.Thanx
murua at 2007-7-28 18:56:26 >

> > I've always wondered...
> >
> > .......................
> > .......................
> > This lack of ability or even interest in
> > debugging their posts doesn't bode well for their
> > ability to produce working code.
>
> It's his first foray into this forum. I can remember
> (not very long ago) being this ignorant or worse.
It's not that he didn't use code tags. It's the lack of curiosity or motivation to even try to fix it after the fact.
Now that he's used code tags, he appears to have copy/pasted the unindented code from here, rather than the properly indented code from his original source.
It's not just this OP. It happens all the time, and shows a distressing lack of certain thought processes that have nothing to do with experience in programming or forum posting.
jverda at 2007-7-28 18:56:26 >

Are you even getting your code to compile? I can't.
> It's not just this OP. It happens all the time, and
> shows a distressing lack of certain thought processes
> that have nothing to do with experience in
> programming or forum posting.
well, you've seen a lot more of this than I have. Let's see how he progresses....
Yes..It's compiling and executing.
murua at 2007-7-28 18:56:26 >

please copy your code from your IDE and repost here. I think your most recent post is missing something. Mine won't even compile. Again, bring it over directly from your IDE.
> Yes..It's compiling and executing.
You didn't just copy and paste your old post did you? all [b] and [i] you had in the code were removed. If so try posting the code again. Hopefully this time it will be indented...
import java.io.*;
import java.lang.*;
import java.util.*;
public class fileinput
{
public static int [][] values;
public static int [][] values1;
public static int [][] newdc;
public static int [][] newdc1;
public static int nr1,nc1;
public static void main(String [] args)
{
int count;
int root1=0;
//int nr1,nc1;
try
{
FileReader fr=new FileReader("C:/thesis/data.txt");
BufferedReader br=new BufferedReader(fr);
String line=br.readLine();
StringTokenizer st=new StringTokenizer(line);
count=st.countTokens();
Double root=Math.sqrt(count);
root1=root.intValue();
values = new int[root1][root1];
values1 = new int[root1][root1];
while ( st.hasMoreTokens() )
{
for(int r=0;r<root1;r++)
for(int c=0;c<root1;c++)
{
values[r][c]=Integer.parseInt(st.nextToken());
}
}
}
catch(FileNotFoundException e)
{
System.out.println("file not found");
}
catch(IOException e)
{
System.out.println("error");
}
System.out.println("DATA CUBE");
for(int i=1;i<root1+1;i++)
System.out.print("" + i);
System.out.println();
for(int r=0;r<root1;r++)
{
System.out.print((r+1) + "");
for(int c=0;c<root1;c++)
System.out.print(values[r][c] + "");
System.out.println();
}
// CREATING PREFIX CUBE
for(int r1=0;r1<root1;r1++)
for(int c1=0;c1<root1;c1++)
{
int vv = getvalue(r1,c1);
values1[r1][c1] = vv;
}
System.out.println("PREFIX CUBE");
for(int i=1;i<root1+1;i++)
System.out.print("" + i);
System.out.println();
for(int r1=0;r1<root1;r1++)
{
System.out.print((r1+1) + "");
for(int c1=0;c1<root1;c1++)
System.out.print(values1[r1][c1] + "");
System.out.println();
}
try
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the 'x' dimension sequence:");
int xbs = Integer.parseInt(in.readLine());
System.out.println("enter the 'y' dimension sequence:");
int ybs = Integer.parseInt(in.readLine());
System.out.println(xbs);
System.out.println(ybs);
nr1=root1/xbs;
nc1=root1/xbs;
newdc = new int[root1][root1];
//newdc1 = new int[nr1][nc1];
for(int i=0;i<nr1;i++)
for(int j=0;j<nc1;j++)
{
int vv = getvalue(i,j);
newdc[i][j]=vv;
}
for (int i=nr1;i<root1;i++)
for(int j=0;j<nc1;j++)
{
int vv = getvalue2(i,j);
newdc[i][j] = vv;
}
for (int i=0;i<nr1;i++)
for (int j=nc1;j<root1;j++)
{
int vv = getvalue3(i,j);
newdc[i][j] = vv;
}
for (int i=nr1;i<root1;i++)
for (int j=nc1;j<root1;j++)
{
int vv = getvalue4(i,j);
newdc[i][j] = vv;
}
System.out.println("New Data Cube");
for(int i=1;i<root1;i++)
System.out.print("" + i);
System.out.println();
System.out.println("--");
for(int i=0;i<root1;i++)
{
System.out.print((i+1) + "|" + "");
for(int j=0;j<root1;j++)
System.out.print(newdc[i][j] + "");
System.out.println();
}
}
catch(IOException e)
{
}
}
public static int getvalue(int i,int j)
{
int valuestemp=0;
for(int a=i;a>=0;a--)
for(int b=j;b>=0;b--)
{
valuestemp = valuestemp + values[a][b];
}
return valuestemp;
}
public static int getvalue2(int i,int j)
{
int valuestemp=0;
for(int a=i;a>=nr1;a--)
for(int b=j;b>=0;b--)
{
valuestemp = valuestemp + values[a][b];
}
return valuestemp;
}
public static int getvalue3(int i,int j)
{
int valuestemp=0;
for(int a=i;a>=0;a--)
for(int b=j;b>=nc1;b--)
{
valuestemp = valuestemp + values[a][b];
}
return valuestemp;
}
public static int getvalue4(int i,int j)
{
int valuestemp=0;
for(int a=i;a>=nr1;a--)
for(int b=j;b>=nc1;b--)
{
valuestemp = valuestemp + values[a][b];
}
return valuestemp;
}
}
murua at 2007-7-28 18:56:31 >

> You didn't just copy and paste your old post did you?
> all [b] and [i] you had in the code were
> removed. If so try posting the code again.
> Hopefully this time it will be indented...
I'm thinking he did causing the errors when I tried to compile, and hence my request for a repeat copy and paste.
now, post the data file....
3 5 1 2 2 4 6 3 7 3 2 6 8 7 1 2 2 4 2 3 3 3 4 5 3 2 1 5 3 5 2 8 4 2 1 3 3 4 7 1 2 3 3 6 1 8 5 1 4 5 2 7 1 9 3 3 2 4 2 2 3 1 9 1.This is an 8x8 array.
murua at 2007-7-28 18:56:31 >

When u give an input as 2 for the 'x' dimension sequence it splits the array in to 4 parts and adds the numbers in each part seperately.The addition part goes like this.If an input (1,1) goes to the getvalue function this gets the the values from (1,1),(1,0),(0,1),(0,0) adds them and stores them in (1,1)
murua at 2007-7-28 18:56:31 >

I still haven't seen a specific question, or any details about what's not working with the code as it exists so far.
jverda at 2007-7-28 18:56:31 >

Your program is very difficult to read and fully understand. You have one huge main method which badly needs to be broken up into smaller submethods. You have variable names that don't tell me what they contain. You have methods that don't have comment blocks at their top to explain what they are supposed to do.
This is not meant as criticism of your code. If it works well for you, fine. It just means that I may not be able to help you.
Also, what's the purpose of all of this?
This code is working fine but it works only for a single input 2.I need to generalize this code so that it works for all inputs
murua at 2007-7-28 18:56:31 >

Sorry..I'll add comments and repost it.I'm jus learnin 2d arrays & 3d arrays
murua at 2007-7-28 18:56:31 >

don't just add comments, you need to refactor,... make submethods and all. But again, what is the purpose of this exercise. Why are you doing this?
> This code is working fine but it works only for a
> single input 2.I need to generalize this code so that
> it works for all inputs
I don't even know what this means.
jverda at 2007-7-28 18:56:31 >

Ok..As I said I'm jus tryin to learn 2D arrays & 3D arrays for a proj that I'm goin to start in another 2 months.
murua at 2007-7-28 18:56:31 >

> Ok..As I said I'm jus tryin to learn 2D arrays & 3D
> arrays for a proj that I'm goin to start in another 2
> months.
Yes, you mentioned that. I don't know what "only works for input of 2 and I need to generalize for any input" means.
What is the "input" here?
Why does it work only for that input and not for others?
jverda at 2007-7-28 18:56:36 >

Ohhk..This is an 8x8 Array right?when i give the input as 2 it should divide the array in to 2^2 parts i:e 4 parts.My code does that perfectly.Now suppose I give an input as 4 it should divide the original array into 16 parts.Hope u understood..
murua at 2007-7-28 18:56:36 >

> Ohhk..This is an 8x8 Array right?when i give the
> input as 2 it should divide the array in to 2^2 parts
> i:e 4 parts.My code does that perfectly.Now suppose I
> give an input as 4 it should divide the original
> array into 16 parts.Hope u understood..
Okay, so what are you doing with 2 that you don't know how to do with 4?
jverda at 2007-7-28 18:56:36 >

Input here is the 'x' dimension sequence.Forget about the 'y' dimension sequence for now..
murua at 2007-7-28 18:56:36 >

> I don't even know what this means.
I think I do know, but am not sure. If you've played Sudoku, you know that it is a 9x9 array, but it is also split up into a 3x3 array of 9 subarrays. I think he is looking to do this in a general sense and then add all the numbers in each subarray (this part I'm not so sure). So he currently is able to take an 8x8 array and split it into 4 4x4 arrays and do his addition on this, but this is not enough for him. He wants to also be able to split it into 16 2x2 arrays, then add those numbers up, but he can't do this just yet. That's my take on all this.
Now why he wants to do this? I have no f***ing idea.
Here's a suggestion: Strip the code down to the minimum.
Get rid of the file input stuff. Get rid of error handling--just let everything throw Exception. In order to get help here, you need to focus on the specific parts that are giving you difficulty. All that other stuff, while necessary for the finished product, is fluff and clutter here.
Just have a hardcoded array. Hardcode the intput "2" or "4" or whatever as well.
Paste just that here. Highlight what in that code makes it work for 2 but not for other values.
jverda at 2007-7-28 18:56:36 >

What my code does is that when i give the input for 'x' dimension sequence as 2 it divides the 8x8 array into 4 equal parts.It does so by finding the middle of the array along both the dimensions and dividing it.Now,wen i give an input as 4 it is not enough if u have only the middle of the array...u need other points in between the array to divide it into 16 parts rite?i'm not sure how to go about doin this.
murua at 2007-7-28 18:56:36 >

> > I don't even know what this means.
>
> I think I do know, but am not sure. If you've played
> Sudoku, you know that it is a 9x9 array, but it is
> also split up into a 3x3 array of 9 subarrays. I
> think he is looking to do this in a general sense and
> then add all the numbers in each subarray (this part
> I'm not so sure). So he currently is able to take an
> 8x8 array and split it into 4 4x4 arrays and do his
> addition on this, but this is not enough for him. He
> wants to also be able to split it into 16 2x2 arrays,
> then add those numbers up, but he can't do this just
> yet. That's my take on all this.
>
> Now why he wants to do this? I have no f***ing idea.
Yes.You've got my idea.This is what i'm tryin to achieve!!
murua at 2007-7-28 18:56:36 >

> What my code does is that when i give the input for
> 'x' dimension sequence as 2 it divides the 8x8 array
> into 4 equal parts.It does so by finding the middle
> of the array
Which is the length divided by 2.
> along both the dimensions and dividing
> it.Now,wen i give an input as 4 it is not enough if u
> have only the middle of the array...u need other
> points in between the array to divide it into 16
> parts rite?
Well, if you want to divide it into 4x4, then you need to divide one axis into 4 parts, and the other axis into 4 parts. If I have N things, and I want to divide it into M equal parts, then each part will have N/M things.
jverda at 2007-7-28 18:56:36 >

You also have to constrain the "input" value from the descriptions you've given.
Sounds like all the matricies must be square, correct?
An 8x8 matrix can be composed into 4 4x4 matricies or 16 2x2 matricies.
A 9x9 matrix can be composed into 4 3x3 matricies.
If the matricies don't have to be square you have a lot more latitude.
Real requirements would be nice.
Some true abstraction would be even better.
I see none here.
%
> You also have to constrain the "input" value from the
> descriptions you've given.
>
> Sounds like all the matricies must be square,
> correct?
>
> An 8x8 matrix can be composed into 4 4x4 matricies or
> 16 2x2 matricies.
>
> A 9x9 matrix can be composed into 4 3x3 matricies.
>
> If the matricies don't have to be square you have a
> lot more latitude.
>
> Real requirements would be nice.
>
> Some true abstraction would be even better.
>
> I see none here.
>
> %
Yup..All matrices must be square
>An 8x8 matrix can be composed into 4 4x4 matricies or
> 16 2x2 matricies.
>
> A 9x9 matrix can be composed into 4 3x3 matricies.
This is exactly what i need.
murua at 2007-7-28 18:56:36 >

> This is exactly what i need.
What is what you need? What are you having trouble with that hasn't been addressed?
jverda at 2007-7-28 18:56:36 >

> Yup..All matrices must be square
Then it's easy.
> This is exactly what i need.
So what's your problem?
Here's the 8x8 case, stored in row order in an array of length 16:
0123
4567
89 10 11
12 13 14 15
So the first 2x2 matrix is (0, 1, 4, 5)
The second 2x2 matrix is (2, 3, 6, 7)
The third 2x2 matrix is (8, 9 , 12, 13)
The fourth 2x2 matrix is (10, 11, 14, 15)
Just write it out for the 8x8 case. It's not that hard.
%
> What is what you need? What are you having trouble
> with that hasn't been addressed?
I'm not able to get an idea of how to divide the array into 16 parts,add the values and store them in another array
murua at 2007-7-28 18:56:36 >

> > What is what you need? What are you having trouble
> > with that hasn't been addressed?
>
> I'm not able to get an idea of how to divide the
> array into 16 parts,add the values and store them in
> another array
One thing at a time. You've got three things going on here:
(1) Divide the array
(2) Add the parts
(3) Store the sums
Computer science is all about divide and conquer. My advice would be to write methods to accomplish each separate task and then knit them together to solve the whole problem.
Or just continue in your present addled, "I don't know what to do" state.
%
> I'm not able to get an idea of how to divide the
> array into 16 parts,
The picture that I gave should help. Just generalize it to a 16x16 array.
> add the values
So adding is hard for you? Back to 2nd grade, then.
> and store them in another array
You don't know how to store numbers in an array?
What you really don't know is how to attack problems. Another student who would rather moan about how they "don't know what to do". As if that's our problem.
Go do something and stop whining.
%
> > What is what you need? What are you having trouble
> > with that hasn't been addressed?
>
> I'm not able to get an idea of how to divide the
> array into 16 parts,add the values and store them in
> another array
Draw the array on paper. Figure out how you'd do it by hand first.
jverda at 2007-7-28 18:56:41 >

> > Yup..All matrices must be square
>
> Then it's easy.
>
> > This is exactly what i need.
>
> So what's your problem?
>
> Here's the 8x8 case, stored in row order in an array
> of length 16:
>
>
>
> So the first 2x2 matrix is (0, 1, 4, 5)
> The second 2x2 matrix is (2, 3, 6, 7)
> The third 2x2 matrix is (8, 9 , 12, 13)
> The fourth 2x2 matrix is (10, 11, 14, 15)
>
> Just write it out for the 8x8 case. It's not that
> hard.
>
> %
Perfect.I jus dont want it to be split in to 4 parts.I want them to be added as well.
>0123
> 4567
> 89 10 11
> 12 13 14 15
1st 2x2 matrix should be (0,1,4,10)
2nd 2x2 matris should be (2,5,8,18)
3rd 2x2 matrix should be (8,17,18,38)
4th 2x2 matrix should be (12,25,26,54)
Basically a particular cell value should add all the values preceding it
murua at 2007-7-28 18:56:41 >

> Basically a particular cell value should add all the
> values preceding it
Huh? Where did this new requirement come from?
First worry about dividing up your array. Then move on to the addition.
jverda at 2007-7-28 18:56:41 >

> Perfect.I jus dont want it to be split in to 4
> parts.I want them to be added as well.
So go ahead and do it. I'm not doing it for you.
>
> >0123
> > 4567
> > 89 10 11
> > 12 13 14 15
>
> 1st 2x2 matrix should be (0,1,4,10)
> 2nd 2x2 matris should be (2,5,8,18)
> 3rd 2x2 matrix should be (8,17,18,38)
> 4th 2x2 matrix should be (12,25,26,54)
Great. If you can do it by hand, you should be able to do it with a program.
> Basically a particular cell value should add all the
> values preceding it
Sounds like a stupid problem. Please go solve it and leave this forum alone.
%
> Huh? Where did this new requirement come from?
< back from dinner>
The addition part has always been there. I'm strugggling to figure out why? I've yet to get an answer.
> > Huh? Where did this new requirement come from?
>
> < back from dinner>
> The addition part has always been there. I'm
> strugggling to figure out why? I've yet to
> get an answer.
Okay, but he's been struggling with dividing the arrays up into equal parts, so he should solve that first.
jverda at 2007-7-28 18:56:41 >

> Okay, but he's been struggling with dividing the
> arrays up into equal parts, so he should solve that
> first.
Agree. That and cleaning up / decluttering his code. It is all one huge main with a few tiny sub methods. Also, no OOP whatsoever.