Be concise.
Be useful.
All contributions dictatorially edited by webmasters to match personal tastes.
Please do not paste any copyright violating material.
Please try to avoid dependencies to third-party libraries and frameworks.
subroutine foo(a)
implicit none
real, dimension(:,:) :: a
real :: s
integer :: i,j
print *,size(a,1), size(a,2)
s = 0
do j=1,size(a,2)
do i=1,size(a,1)
s = s + a(i,j) * i * j
end do
end do
print *,s
end subroutine foo
!
call foo(a)
/**
* @param {Array<Array>} arry
*
* @return {Array<Array>}
*/
function foo(arry) {
let len = 0;
let sum = 0;
arry.forEach(function(base, i) {
len += base.length;
base.forEach(function(a, j) {
sum += a * (i + 1) * (j + 1);
});
});
console.log('Array size:', arry.length, ',', len);
return sum;
}
foo(arry2d);
public static void foo(int[][] a){
System.out.println("Array a has a size of " + a.length+" by " + a[0].length);
int sum = 0;
for (int i = 0; i<a.length; i++){
for (int j = 0; j<a[0].length; j++){
sum += ((i+1)*(j+1)*a[i][j]);
}
}
System.out.println("The sum of all elements multiplied by their indices is: " + sum);
}
procedure foo(a: array of double);
var
sum: double;
i: Integer;
begin
for i := low(a) to high(a) do
sum := sum + (i+1)*a[i];
writeln('Size = ',Length(a),', Sum = ',sum:6:5);
end;
...
foo(a);
...
def foo(a):
print(len(a))
print(sum(
x*(i+1) + y*(i+1)*2 for i, (x, y) in enumerate(a)
))
def foo(a):
z = 0
for i, x in enumerate(a, 1):
for j, y in enumerate(x, 1):
# z = z + (y * i) + (y * j)
z = z + (y * i * j)
print(len(a), z)
foo(a)
def foo(ar)
puts "Array size: #{ar.size}, #{ar.max.size}."
ar.each.with_index(1).sum do |a, i|
a.each.with_index(1).sum do |el, j|
el*i*j
end
end
end
puts foo(array)