Imagine I have a number that is all the numbers in the universe stuck to eachother, from 1 to infinity. (123456789​1011121314​1516171819​20212223..​.). How can I write a code that says: If I have a number n, what is the nth digit of this gigantic number?

조회 수: 1 (최근 30일)
I couldn't come up with a solution yet

답변 (1개)

michael
michael 2016년 10월 8일
just use
mod, floor
functions
a=17
b=a
mod(b,10) <=== you will get 7
repeat till the n-th digit (n=2)
b=floor(b/10)
mod(b,10) <=== you will get 1

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by