Created
May 20, 2020 15:01
-
-
Save unalfaruk/85117fd3309158a52f892a75b13d59d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function result = isKaprekarNumber(number) | |
result=0; | |
lenOfNumber = length(num2str(number)); | |
numberArray = num2str(number); | |
sqOfNumber = number.^2; | |
sqNumberArray = num2str(sqOfNumber); | |
sqHead= sqNumberArray(1:lenOfNumber); | |
sqTail= sqNumberArray(lenOfNumber+1:lenOfNumber+lenOfNumber); | |
sumOfHeadAndTail = str2num(sqNumberArray(1:lenOfNumber))+str2num(sqNumberArray(lenOfNumber+1:lenOfNumber+lenOfNumber)); | |
if isequal(number,sumOfHeadAndTail) | |
result=1; | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment