Using 2-dimensional Array In C++ - Programming - Nairaland
Nairaland Forum › Science/Technology › Programming › Using 2-dimensional Array In C++ (2640 Views)
1 Reply
| Using 2-dimensional Array In C++ by Vicony4real(op): 11:05pm On Mar 21, 2013 |
How can i get started with a program to add, multiply and sum the square of two 2-dimensional array in c++. This is strictly for academic purpose, with monday as deadline. Thanks in anticipation of yooour help. thanks. |
| Re: Using 2-dimensional Array In C++ by blenyo11(m): 9:22am On Mar 22, 2013 |
I am assuming that the size of the two arrays is the same and you are to add the corresponding elements. you can start with this #include <cstdlib> #include <iostream> using namespace std; int main(int argc, char *argv[]) { int array1[2][2]; //creates a 2*2 matrix or a 2d array. This array 1 int array2[2][2]; //creates a 2*2 matrix or a 2d array. This array 2 //let fill the the two arrayss with some random values. This is up to you to change since I don't know the values you are given for(int i=0; i<2; i++) //This loops on the rows. { for(int j=0; j<2; j++) //This loops on the columns { array1[i][j] = i; array2[i][j] = i + 3; } } //Let get the addition done for(int i=0; i<2; i++) //This loops on the rows. { for(int j=0; j<2; j++) //This loops on the columns { cout << array2[i][j] + array1[i][j] << endl; } } cout << endl; //Let get the subtraction done for(int i=0; i<2; i++) //This loops on the rows. { for(int j=0; j<2; j++) //This loops on the columns { cout << array2[i][j] - array1[i][j] << endl; } } cout << endl; system("PAUSE" ) ; return EXIT_SUCCESS; } One thing you should pick from this and then build on is the ability to read a value at a specific index |
| Re: Using 2-dimensional Array In C++ by Vicony4real(op): 12:31am On Mar 23, 2013 |
blenyo11: I am assuming that the size of the two arrays is the sameThanks so much, am grateful. is it possible to readthe input from a file? as in making use of the #include<fstream> if possible, how can that be done? thanks again... |
Need A Developer For A Three Dimensional Store • Help With Fftw 3 Dimensional • Converting Picture To Byte Array(blob) And Back To Picture • 2 • 3 • 4
Are There Any Json, Rss Or Xml Feeds For Nairaland? • Whatsapp Co-founder Jan Koum Quits Over Privacy Disagreements With Facebook • Help With This Regular Expression: