Imagine I have a number that is all the numbers in the universe stuck to eachother, from 1 to infinity. (1234567891011121314151617181920212223...). 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
0 件のコメント
回答 (1 件)
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
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!