필터 지우기
필터 지우기

writing a program on matlab

조회 수: 1 (최근 30일)
m_vdv
m_vdv 2018년 2월 18일
댓글: Walter Roberson 2018년 2월 18일
Hi, I have to write a program that asks you to enter a number and then shows how many digits it has. Who can help me?
  댓글 수: 1
Walter Roberson
Walter Roberson 2018년 2월 18일
The first step is to define exactly all of the forms of representation of numbers that are to be permitted. For example, is the user permitted to have spaces between a negative sign and what follows? When the number has absolute magnitude less than 1, is the user permitted to omit the leading 0? Which exponent characters are permitted? Is the optional '+' allowed for positive exponents? What is the maximum length of input that is required to be processed properly? Will you permit Ɔ and ↀ when the user gives Roman Numeral input?

댓글을 달려면 로그인하십시오.

채택된 답변

Birdman
Birdman 2018년 2월 18일
a=input('Enter a number\n');
dig=numel(num2str(a))
  댓글 수: 3
Image Analyst
Image Analyst 2018년 2월 18일
If you don't want to count decimal points (commas or dots), you can do this:
str = input('Enter a number ');
% Convert to string
str = num2str(str)
% Get rid of decimals and commas
str = strrep(str, '.', '');
str = strrep(str, ',', '');
% Now count digits
numberOfDigits = numel(str)
Walter Roberson
Walter Roberson 2018년 2월 18일
numel(num2str(18446744073709551615))
ans =
21
>> numel('18446744073709551615')
ans =
20

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by