Question:
How to determine number of digits of integer numbers between 1 & 99999 in MATLAB?
Answer:
Number of digits can easily be determine by converting number to string and then count them. In MATLAB, "num2str" is used to covert number to string and "numel" is used to count.
clear all; clc; close all a = input('Enter an integer number between 1 & 99999:'); a_num = numel(num2str(a)); fprintf('The number of digits are: %d',a_num)
OUTPUT
ATTEMPT I:
Enter an integer number between 1 & 99999: 543 The number of digits are: 3
ATTEMPT II:
Enter an integer number between 1 & 99999: 9988 The number of digits are: 4
0 Comments