Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

#Day61 #100DaysChallenge- Matlab Loops| Palindrome or Not

#Day61-Palindrom or Not
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

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

Sample Input and Output

>> 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 =


     0     2     0     2     2     0     2     5 

Click here for Video Description


Free Codes: youtube.com/castorclasses



Live Support: t.me/matlabirawen



No comments

Popular Posts

Followers