#Day61 #100DaysChallenge- Matlab Loops| Palindrome or Not
#Day61-Palindrom or Not
Task:
Task:
Write a code to find if the given vector is palindrome or not
x=[0,2,0,2,2,0,2,0] Palindrome.
x='MADAM' Palindrome.
x=[1,2,3,4] Nor a Palindrome.
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.
Matlab code
Sample Input and Output
0 2 0 2 2 0 2 5
Click here for Video Description
Free Codes: youtube.com/castorclasses
x=[0,2,0,2,2,0,2,0] Palindrome.
x='MADAM' Palindrome.
x=[1,2,3,4] Nor a Palindrome.
Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.
Matlab code
function reversed= reversinggiveninput(x)
n=length(x);
for i=n:-1:1
reversed((n+1)-i)=x(i);
end
if x==reversed
fprintf('The
given vector is palindrom');
end
>> x=['madam']
x =
'madam'
>> reversed= reversinggiveninput(x)
The given vector is palindrom
reversed =
'madam'
>> x=['radar']
x =
'radar'
>> reversed= reversinggiveninput(x)
The given vector is palindrom
reversed =
'radar'
>> x=[0,2,0,2,2,0,2,0]
x =
0 2 0 2 2 0 2 0
>> reversed= reversinggiveninput(x)
The given vector is palindrom
reversed =
0 2 0 2 2 0 2 0
>> x=[0,2,0,2,2,0,2,5]
x =
No comments