mathametical operations on multi dimentional arrays

tayyab

Member
Joined
Jun 27, 2006
Messages
5
Programming Experience
Beginner
hello, my name is tayyab and i am new to vb.net, i hav a question

how we can performs mathematical operations like adding, subtracting etc....... with multi dimentional arrays.

i have tried and get it through with normal arrays i m attaching the program of addition of normal arrays.

but anyone can help me in addition of multi dimentional arrays

thanks
 

Attachments

  • datastructure assignment.zip
    23.8 KB · Views: 12
Last edited by a moderator:
Hello tayyab and welcome :)

I'm not quite sure what you're asking here, (I cant open the project as I have vs2003) Do you want to be able to add all the elements of an array together? if so you could do a nested for loop statement something like:

VB.NET:
Dim myArray(4,6) as integer
Dim myNum as integer

For x as integer = 0 to 4

For y as integer = 0 to 6

myNum += myArray(x,y)

Next

Next
Not sure if thats what you want but i hope it helps
 
I've edited the attached file to remove the binary files. If you want to attach projects please remove the "bin" and "obj" folders before doing so. Having said that, it's preferable to avoid attaching entire projects unnecessarily. If you want help with a piece of code then post the code. We don't need the entire project.

As Craig implies, a multidimensional array is simply a matrix. You get an element at a specific location by specifying the index of that element in each dimension. A 2D array is just like specifying X and Y coordinates on a graph. Anything above three dimensions gets hard to visualise but the principles are the same regardless of the number of dimensions, plus array with greater than three dimensions would be relatively rare anyway.
 
thanks Craig for your help i will try to do as hav suggested and next time i will take care about the forums rules and will post the coding etc....

thanks
 
i am writing my incomplete codes here

VB.NET:
Dim matrix(2, 2), i, x AsInteger
 
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For i = 0 To 2
matrix(i, i) = InputBox("please enter the First Column")
Next
For i = 0 To 2
TextBox1.AppendText(matrix(i, i))
TextBox1.AppendText(vbCrLf)
Next
For x = 0 To 2
matrix(x, x) = InputBox("please enter the Second Column")
Next
For x = 0 To 2
TextBox2.AppendText(matrix(x, x))
TextBox2.AppendText(vbCrLf)
Next
EndSub


i m taking the input's in textbox1 and textbox2, and my requirment is how to add the textbox1 and textbox 2 and get the answer in textbox3,
plz someone help
thanks,
 
Last edited:
I'm sorry I still dont understand what you are trying to do

Also with your for..loops you will only be setting values matrix(0,0), matrix(1,1), matrix(2,2) and missing out (0,1) (0,2) etc etc which is why you need nested statements
 
i m trying to add two multi dimentional arrays in textbox , in my coding above i hav taken input form user in textbox1 and textbox2. its output is similar to this


VB.NET:
textbox1 textbox2 textbox3
   1             8          need to add the values of textbox1 and 2 in textbox3
   2             6          need to add the values of textbox1 and 2 in textbox3
   3             5          need to add the values of textbox1 and 2 in textbox3


i need to add the textbox1 value with textbox2 and then display the result in textbox3.

hope it helps u in understanding what i m trying to do.

thanks waiting for ur reply
 
Back
Top