In: Computer Science
Using Matlab
Program:
clc;
function digits_function(n) % function definition
num = n; % store the value n in num
number_digits = 0; % Assign count to 0
sum_digits = 0; % Assign sum_digits to 0
mul_digits = 1; % Assign mul_digits to 1
while (n > 0) % Loop to check n>0
sum_digits += mod(n,10); % Calculate sum of digits
mul_digits *= mod(n,10); % Calculate mutiplication of digits
n = fix(n / 10); % perform integer division
number_digits++; % increment countnumbe_digits by 1
end
fprintf("Number of digits in %d is %d\n",num,number_digits);
% print the number and number of digits
fprintf("Sum of digits in %d is %d\n",num,sum_digits)
% print the sum of digits
fprintf("Multiplcation of digits in %d is
%d\n",num,mul_digits)
% print the multiplication of digits
fprintf("\n"); % print new line
end
Output: