m=sum(diag(magic(n)))
m= magic_sum(n)
z=magic(n);
m=sum(z(:));
why this aint working
@Anshul, Because here we want the sum of particular row, and your soln defines the sum of all the elements in the matrix!
@harsh thanks
nice question
Good one
function m = magic_sum(n)
x = magic(n);
y = sum(x);
m= randsample(y,1);
end
why it is wrong?
function m = magic_sum(n)
t=magic(n)
m=sum(t(1:n));
end
temp=sum(magic(n),1); m=temp(1);
its hard
Sum of first n terms of a harmonic progression
257 Solvers
347 Solvers
Piecewise linear interpolation
299 Solvers
238 Solvers
480 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!