Programming and Graphics

(Kiana) #1

4.6 Functions with array arguments 115


//..................

cout << " Projected vector at stage: " << icount;
cout << "\n\n";

for (i=1;i<=n;i++)
{
cout << setprecision(5) << setw(10);
cout << b[i] << endl;
}

icount = icount+1;

cout << " One more projection? "<< endl ;
cin >> more;
}
return 0;
}

/*-------------------------------------------------
function matvec performs matrix-vector
multiplication: ci=aij bj
--------------------------------------------------*/

void matvec (int n, double a[][50], double b[], double c[])
{
int i, j;
for (i=1;i<=n;i++)
{
c[i] = 0;
for (j=1;j<=n;j++)
{
c[i] = c[i] + a[i][j]*b[j];
}
}
}

The content of the filematixv.datis:


5
1.0 -2.0 3.0 1.2 2.6
-4.0 2.0 -3.0 8.9 -5.9
3.0 -3.0 3.0 -2.7 0.1
1.2 8.9 -2.7 3.2 1.3
2.6 -5.9 0.1 1.3 -0.2

0.1 0.4 -0.2 -0.1 -2.9
Free download pdf