John Stevens

Greenhorn
+ Follow
since Oct 24, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by John Stevens

I have various function calls in a program:
//FUNCTION CALLS
enterDiagonal(matrix, sizeIn);
enterBelowDiagonal(matrix);
enterAboveDiagonal(matrix);
PrintTri(matrix, sizeIn);
int [] oneD = storeTo1D(matrix, sizeIn);
int [] Vectwo = setUpVector2(sizeIn);
int [] sumarr = AddOrSub(sizeIn, oneD, Vectwo);
storeTo1D(matrix, sizeIn);
setUpVector2(sizeIn);
AddOrSub(sizeIn, oneD, Vectwo);
displayarray(oneD, Vectwo, sumarr);
The int[] declaration in the middle indicate the use of local function variables in other functions.
The problem I am having is one the function 'AddOrSub(sizeIn, oneD, Vectwo);' is finished, it seems to go all the way back to 'storeTo1D(matrix, sizeIn);'.
I don't understand why its doing this but Iam pretty sure its those int[] reference declarations that are causing this. I've tried switching them around bu no luck.
Can anyone point me in the right direction?
Thanks.
15 years ago
If I have for example the following code in one function e.g. Function3:
for(int k = 0; k < sumarr.length; k++)//to print into new array(display only)
{
for(int i = 0; i < oneD.length; i++)//loop through 1st array
{
for(int j = 0; j < Vectwo.length; j++)//loop through second array
{
sumarr[k] = oneD[i] + Vectwo[j];//e.g. sumarr[0] = oneD[0] + Vectwo[0]
}
}
The arrays oneD and Vectwo were decalred in 2 seperate functions e.g. FunctiononeD and functionVectwo.
How do I use these arrays (oneD and Vectwo) in function 3 if I declared them outside main. How do I call it in main and what would be the function heading in finction3?
15 years ago
I want to store the values of a 2D array into a 1D array depending on the values of the 2D array.
For example:
int[] oneD = new int [val]; //value of 1D array depends on value of 2D

for (int i = 0; i < oneD.length; i++)//for loop for 1D array
{
for (int row = 0; row < matrix.length; row++)
{
for (int col = 0; col < matrix.length; col++)
{
if(matrix[row][col] > 0)
{
oneD[i] = matrix[row][col];
}
}
}
}
If the value of the 2D array is more than zero than store that value in the 1D array.
When I display the values of the 1D array it displays the last value of the 2D array continuously in each element of the 1D array.
How can I correct this?
15 years ago
Just an extension of my last post on Tridiagonal matrix.
I've got for example the following matrix:
1 4 0 0
1 3 5 0
0 3 4 4
0 0 6 6
How do I store only the non-zero numbers in a one dimensional array in this order:
1, 4, 1, 3, 5, 3, 4, 4, 6, 6
???
15 years ago
I am trying to construct a tridiagonal matrix.
The stipulation of this kind of matrix is the number of rows is equal to the number of columns and non-zero entries should only exist on the main diagonal and above and below the main diagonal e.g. this 6x6 array.
6 8 0 0 0 0
2 6 3 0 0 0
0 3 6 3 0 0
0 0 9 6 1 0
0 0 0 5 6 5
0 0 0 0 1 6

The main diagonal elements of this matrix are 6, 6, 6, 6, 6, 6.
How can I implement a program that obeys these rules when for example I want a user to enter the the size of the matrix and values in this matrix?
Thanks for the help
15 years ago