Help with MATLAB problemSolution matlab code to find first n
Help with MATLAB problem.
Solution
% matlab code to find first n prime number
%returns true is number is prine, else false
 function bool = is_prime(number)
 bool = true;
 for i = 2:number-1
 if mod(number,i) == 0
 bool = false;
 break
 end
 end
 end
 % driver code
 number = input(\"Enter the number of primes you would like to display: \");
 count = 0;
 i = 2;
 while count != number
 bool = is_prime(i);
 if bool == true
 fprintf(\"%d \", i);
 count = count + 1;
 end
 i = i + 1;
 end
%{
 output:
 Enter the number of primes you would like to display: 20
 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71
 %}

