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

LASTNAME LAB10 TASK3 LASTNAME LAB10 TASK3 Enter an integer: Enter an integer 14.

ID: 3812605 • Letter: L

Question

LASTNAME LAB10 TASK3 LASTNAME LAB10 TASK3 Enter an integer: Enter an integer 14.5 Enter a digit number to find (0 to 9): 0 Invalid input Try again! contains 1 digits. Enter an integer: 122333444455555 occurrence frequency of digit 0 is 1 a digit number to find (0 to 9): 20 Invalid input Try again LASTNAME LAB10 TASK3 Enter a digit number to find (O to 9) -3 Enter an integer: Try again Invalid input Enter a digit number to find CO to 9): 3 Integer 122333444455555 contains 15 digits Integer 15 digits frequency of digit 3 is 3 occurrence frequency of digit 5 is 5. LASTNAME LAB10 TASK3 LASTNAME LAB10 TASK3 Enter an integer 122333444455555 an integer Enter digit number to find (0 to 9): 3 Enter a digit number to find (0 to 9): 1 Integer 122333444455555 contains 15 digits. contains 1 digits. occurrence frequency of digit 1 is 0 occurrence frequency of digit 3 is 3. (a) [12 points Prompt the user to enter a scalar integer and store the integer in a variable named integerInput. Assume the user will always enter a numerical scalar that does not contain any leading zeros. Utilize awhile-end statement to continuously prompt the user until the user actually enters an integer. You may use the built-in round function to help you determine whether or not the user entered an integer scalar.

Explanation / Answer


integerinput=1.5;

while(round(integerinput)!=integerinput)

integerinput=input('enter an integer: ');

end


digittofind=-1;

while(digittofind<0||digittofind>9)

digittofind=input('enter a digit between 0-9: ');

end


digittofindfreq=0;
numofdigits=0;
while(integerinput!=0)

numofdigits=numofdigits+1;
num=floor(integerinput/10);

lsd=integerinput-(num*10);

if(lsd==digittofind)
  
digittofindfreq=digittofindfreq+1;
  
end

integerinput=num;
end

fprintf('number of digits: %d ',numofdigits);
fprintf('frequency of the given number : %d ',digittofindfreq);