In: Computer Science
Using MATLAB or Octave, Write a script that prompts the user for a multiplier, storing it in the variable fMultiplier. The script should them prompt the user for a number, storing it in the variabl fIn. The script should then calculate the product of these two variables, saving the result to another variable fOut, and printing it. The script should then repeat the prompt for fIn, calculation, and output twice more, using the same variable fIn and fOut all three times. Sample output: Enter a multiplier: 13 Enter a number to multiply the multiplier by: 0.5 The result of 0.5000 * 13.0000 is 6.5000 Enter a number to multiply the multiplier by: 10.2 The result of 10.2000 * 13.0000 is 132.6000 Enter a number to multiply the multiplier by: -1.1 The result of -1.1000 * 13.0000 is -14.3000 Enter a multiplier: 3.1 Enter a number to multiply the multiplier by: 200 The result of 200.0000 * 3.1000 is 620.0000 Enter a number to multiply the multiplier by: -2.12 The result of -2.1200 * 3.1000 is -6.5720 Enter a number to multiply the multiplier by: 11.11 The result of 11.1100 * 3.1000 is 34.4410
MATLAB Code:
% Script that calculates multiplication three times with same
multiplier
% Reading multiplier
fMultiplier = input("Enter Multiplier: ");
% Repeating three times
for i=1:3
% Reading fin
fin = input("Enter a number to multiply the multiplier by:
");
% Calculating fout
fout = fin * fMultiplier;
% Printing result
fprintf("The result of %.4f * %.4f is %.4f\n", fin, fMultiplier,
fout);
end % For end
___________________________________________________________________________________________________
Sample Run: