Search This Blog

#Day49#100DaysChallenge- Matlab Loops| Prime or Composite Number

#Day49- Prime or Composite Number

Task:

Write a code to find a given number is prime or Composite.

               

1-Neither prime nor composite Number

87-Prime number

78-Composite Number

               

Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those

MATLAB Code: 

function primeornot(x)

if (x/1)==1

    fprintf('Neither prime nor composite Number');

elseif mod(x,2)~=0||(x/2)==1

  

    fprintf('Prime number');

else

    fprintf('Composite Number');

end

end

 

Sample Input and Output

>>primeornot(78)

Composite Number

>> primeornot(1)

Neither prime nor composite Number

>> primeornot(19)

Prime number


No comments

'; (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); })();