Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

#Day2- #100DaysChallenge- Matlab Loops| Get a single Digit

#Day2-Get a single Digit

Task: Write a function that accepts only a single-digit value from 1 to 9 as input, if it is not within the given limit then print as Invalid output and ask the user to enter the input until they enter a single digit.

Matlab Code:

function digit=get_digit()

while digit==0     % continue untill input is single digit
    in=input('Enter  a digit');
    if (in<=9) && (in>=0) && (mod(in,1)==0)  % condition  to check if the given value is single digit or not    
     fprintf('invalid Output\n');  %printing output value

Sample Input:


Enter  a digit 3456789

invalid Output

Enter  a digit -89

invalid Output

Enter  a digit  567

invalid Output

Enter  a digit 34

invalid Output

Enter  a digit 5

digit =


Click Here for Code explanation

Join us on Telegram: Join us on Facebook Group:

No comments

Popular Posts