X = [12 43 11 52 47 3 45 62 14 23 51]; Create main file exampb3.m and use for lo
ID: 3837535 • Letter: X
Question
X = [12 43 11 52 47 3 45 62 14 23 51]; Create main file exampb3.m and use for loop, isprime command, if structure, counter logic to count how many numbers are not prime numbers in 'x'. The command isprime works as follows: isprime(5) will give answer 1 because 5 is prime number. isprime(8) will give answer 0 because 8 is not a prime number. Use for loop to check each number of vector 'x' and if it that number is not a prime number, increment the counter. Display the final counter value in command window.Explanation / Answer
% The following code is written in Matlab and it iterates through the vector x. Each time if the value of x is not a prime then the count is incremented. Final count is displayed.
count = 0; %set count to 0
for x = [12 43 11 52 47 3 45 62 14 23 51];
if(isprime(x) == 0)
count = count + 1;
end
end
disp(count);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.