Return the first N perfect squares Example input = 4; output = [ 1 4 9 16 ]; MATLAB CODE: clc clear all close all x=input('Enter the number:'); Y=[]; g=length(Y); m=1; while(g<x) y=sqrt(m); z=ceil(y); if(z==y) Y=[Y m]; g=length(Y); end m=m+1; end Explanation:
No comments