MATLAB Answers

How do I replace the last value in the output string to 'and *value*.' instead of ', *value*,'?

3 views (last 30 days)
How do I replace the last value in the output string to 'and *value*.' instead of ', *value*,'?
Any help is greatly appreciated!
Current output:
list: ... 53 (prime), 54, 55,
Desired output:
list: ... 53 (prime), 54 and 55.
Question mostly answered already below!

  0 Comments

Sign in to comment.

Accepted Answer

Image Analyst
Image Analyst on 3 Dec 2019
Try
for i = 1 : N
fprintf('%d', i);
if ismember(i, result)
fprintf(' (prime)');
end
if i < N
fprintf(', ');
else
fprintf('.\n');
end
end

More Answers (0)

Sign in to answer this question.