1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <iostream>
using namespace std;
void Column_SUM ();
int i, j, num[3][5];
int main ()
{
for (i=0; i<2; i++)
{
for (j=0; j<4; j++)
{
cout << "Enter [" << i << "][" << j << "] numbers : ";
cin >> num[i][j];
}
cout << "\n";
}
cout << endl;
Column_SUM(); // you FAILED to use the function at all,
return 0;
}
/* if you want to use data stored in variable(s) you can declare the function
as int Column_SUM(int input1, int input2) and assuming we have previously
declared and stored values in variables int number1, and int number2, we can
call the function in the manner Column_SUM(number1,number2); now
remember that you use the variables input1 and input2 within your function,
of course you might want to make it return a value of some sort, say...return input1*input2;
and if you use it as int mytimesd=Column_SUM(number1,number2); the value of input1 * input2 will
be stored in mytimesd, of course it will be the same as number1*number2,
and after the function is finished, the temporary variables input1 and input2
are destroyed, so don't expect to use them outside of the function.
SORRY SO LONG
*/
void Column_SUM ()
{
int colsum[3]={0};
for (i=0; i<2; i++)
{
for (j=0; j<4; j++)
colsum[i] += num[i][j];
}
for (int d=0; d<3; d++)
cout << colsum[d] << endl;
return;
}
|