previous | next |
The purpose is to illustrate the power of pass by name. We will
use c-like syntax.
int sum (int a, int index,int lower, int upper) {
int temp = 0;}
for(index=lower, index<=upper;index ++){temp = temp+a;}
return temp;
int n;
int x[ ]=new int[10];
int y[ ]=new int[10];
int i, Ten_ns, xtotal, inner-prod;
Ten_ns = sum(n,i,0,9);
xtotal = sum(x[i],i,0,9);
inner-prod = sum(x[i]*y[i],i,0,9);
sum(n,i,0,9) executes{ temp=0;
sum(x[i],i,0,9) executes
for(i=0,i<=9,i++){
temp = temp + n ;
}
return temps;
}{ temp=0;
for(i=0,i<=9,i++){
temp = temp + x[i] ;
}
return temps;
}
sum(x[i]*y[i],i,0,9) executes
{ temp=0;
for(i=0,i<=9,i++){
temp = temp + x[i]*y[i] ;
}
return temps;
}
previous | next |