Any questions about Assignment 1.
public int Ex1( int A[] ) { // compute sum of elements of A int s = 0; for( int i=0; i < A.length; i++ ) { s += A[i]; } return( s ); } public void Ex2( int A[], int B[] ) { // store the prefix sums of A into B int i,j,s; for( i=0; i < A.length; i++ ) { s = 0; for( j=0; j <= i; j++ ) { s += A[j]; } B[i] = s; } } public void Ex3( int A[], int B[] ) { // store the prefix sums of A into B int i,s; s = 0; for( i=0; i < A.length; i++ ) { s += A[i]; B[i] = s; } } public void Ex4( int A[], int B[] ) { // store the prefix sums of prefix sums of A into B int i,j,k,s; for( i=0; i < A.length; i++ ) { s = 0; for( j=0; j <= i; j++ ) { for( k=0; k <= j; k++ ) { s += A[k]; } } B[i] = s; } }Can
Ex4()
be re-written so that it runs faster? How much faster?