Advertisement
BORUTO-121

divide_number_to_prime_factors(2)

Mar 6th, 2022
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.69 KB | None | 0 0
  1. try
  2.     A=1024;
  3.     B=f1(A);
  4.     disp(B);
  5. catch exception
  6.     disp(exception)
  7. end
  8.  
  9. function [B]=f1(A)
  10.     if(A<0 || fix(A)~=A)
  11.         H=MException('myComponent:inputErro','Doslo je do greske');
  12.         throw(H);
  13.     end
  14.    
  15.     if(A==0 || A==1)
  16.         B=A;
  17.         return;
  18.     end
  19.    
  20.     j=1;i=2;
  21.     while A~=1 && i<=A
  22.         if(notPrime(i)==0 && mod(A,i)==0)
  23.             B(j)=i;j=j+1;
  24.             A=A/i;i=1;
  25.         end
  26.         i=i+1;
  27.     end
  28. end
  29.  
  30. function [y]=notPrime(number)
  31.         y=0;
  32.             for i=2:fix(sqrt(number))
  33.                 if(mod(number,i)==0)
  34.                     y=1;
  35.                     break;
  36.                 end
  37.             end
  38. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement