Write a program that prompts the user to enter a positive in
Write a program that prompts the user to enter a positive integer then finds and prints how many odd, how many even, and how many zero digits are there in the number. Enter a positive integer: 4058760 There are 2 odd, 2 zero, and 3 even digits
Solution
%clearing window and variables
clear all;
clf;
clc;
A=input(\'Enter the positive integer:\'); %Requesting the number from the user
z=0;
o=0;
e=0;
while(A>0)
n=mod(A,10); %DERIVING THE INDIVIDUAL NUMBERS
if (n==0) %VERIFYING WHETHER ZERO
z=z+1;
elseif (mod(n,2)==0) %VERIFYING WHETHER EVEN
e=e+1;
else
o=o+1;
end
A=floor(A/10);
end
fprintf(\'\ Ther are %d odds, %d zeroes and %d even digits.\ \',o,z,e); %Outputting the values
Results;
Enter the positive integer:160097
Ther are 3 odds, 2 zeroes and 1 even digits.
