about palindrome number check
Show older comments
%i have number n and i want to check whether that is palindrome
%but the n is too big so i cant use this code,what should i do
%example n= 1.76536927729736e+16
%my code is
if n==str2num(flip(num2str(n)))
flag=true
else
flag=false
end
5 Comments
"what should i do"
First you have to store the number using a data class that has sufficient precision for the number of digits you require (this might be char), otherwise any operations you perform on that number are meaningless.
How is the number provided to you?
Nguyen Huy
on 14 May 2021
"...the calculation alway return result have 'e+',i have tried %format long"
The format command only controls how numbers are displayed, it it totally unrelated to how numeric values are stored.
"how can i store enough precision for the number of digits"
That really depends on the number of digits that you need to store, which so far you have not told us. General solution for arbitrary number of digits: use char.
How do you get this number: Is the number provided in a text file? Or in a binary file? Or via an automated code-checking tool that your school uses? Or do you have to enter it by hand / copy-and-paste it from your assigment task?
Nguyen Huy
on 14 May 2021
Stephen23
on 14 May 2021
As Jan wrote you could store the digits as CHAR or UINT8, which also makes your palindrome checking easy.
Accepted Answer
More Answers (0)
Categories
Find more on Identify Code Issues in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!