Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The way you typically see an fprintf is with an opening string constant that rep

ID: 3860256 • Letter: T

Question

The way you typically see an fprintf is with an opening string constant that represents the format for the following items. Note that in many instances whether you use 3.14159 (a numeric literal) or pi (a numeric variable, though in this case it is predefined) interchangably. This is also true of string literals (in quotes) and string variables. Knowing this, what will be printed by the following? Are the correct answers being produced? If not, show how to fix the code. f = ['The number %d is odd ': 'The number %d is even ']: for ii = 1: 5 fprintf (f (mod(ii, 2)+1), ii): end

Explanation / Answer

% plz comment and upvote,,if u find the answer useful.....Thanx ;-)
% Modified and working code
f = {'the number %d is even ';'the number %d is odd '};

for i = 1:5
    fprintf(f{mod(i,2)+1},i);    % to acess an element in a table we have to access like this f{1} or f{2}
end