Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

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

Popular Posts

Followers