Write
a script to check whether entered number is prime number or not. If number is
prime then print its square value.
n=input('Pick
a number:\n');
count=[2:1:n+5];
k=1;
c=0;
while
count(k)~=n
if(rem(n,count(k))~=0)
k=k+1;
else
c=c+1;
end
end
if
c==0
fprintf('%d is prime',n);
fprintf('and its square is %d ',n^2);
else
fprintf('%d is not prime',n);
end
OUTPUT
Pick a
number:
3
3 is
prime and its square is 9
No comments:
Post a Comment