S = [];
for i = 1:7
S(end+1) = print_s(i);
fprintf("\n");
end
fprintf("%g^2 ",sqrt(S));
function res = print_s(n)
res = 0;
for i = 1:2:(2*n-1)
res = res + i;
fprintf("%d",i);
if(i==2*n-1)
fprintf("=");
else
fprintf("+");
end
end
fprintf("%d",res);
end
Cite As
Hoi Sing Lau (2026). n square (https://www.mathworks.com/matlabcentral/fileexchange/182207-n-square), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2024b
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Acknowledgements
Inspired by: Find numbers which can be expressed as Sum of Squares of Positive Integers
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0 |
