MATLAB using ASCII Values (Use of 32 number in programming)

preview_player
Показать описание
Question:

Convert characters of a string to opposite case

**Code is given in the comment section**
Рекомендации по теме
Комментарии
Автор

CODE :


x=input('Enter the name:');
q=double(x);
for i=1:length(q)
if(q(i)>=65 && q(i)<=90)
q(i)=q(i)+32;
elseif(q(i)>=97 && q(i)<=122)
q(i)=q(i)-32;
end
end
a=char(q)


***NOTE***
If you don't give the second condition & write the code like this:

x=input('Enter the name:');
q=double(x);
for i=1:length(q)
if(q(i)>=65 && q(i)<=90)
q(i)=q(i)+32;
else
q(i)=q(i)-32;
end
end
a=char(q)

then if space is given by user in between name & surname, then the integer corresponding to space is 32 & 32+32=64 which corresponds to @ character . To avoid this type of problems I have given that second condition too :-)

KnowledgeAmplifier
welcome to shbcf.ru