Search This Blog

#Day47 #100DaysChallenge- Matlab Loops|Finding Number of Digits in Given Number

#Day47-Finding Number of Digits in Given Number
Task:
Write a code to find number of digits in the given number.
78096633
Number of Digits:8

Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.

Matlab code


function count=numberofdigits(x)

count=0;

while floor(x)>0
x=x/10;
count=count+1;
end
end



Sample Input and Output
>> numberofdigits(9650)

ans =

     4

>> numberofdigits(9650987654)

ans =


    10
Click here for Video Description







Live Support: t.me/matlabirawen


No comments