asks the user for a word in the form of a string using matlab
asks the user for a letter
check to see if the letter is contained in the word
if the letter is not contained, prints out sorry
if the letter is contained print out the word
%matlab code
word = input('Enter a word: ', 's');
letter = input('Enter a letter: ', 's');
flag = 0;
% put flag 1 is letter is found in word
for i=1:length(word)
if word(i) == letter
flag = 1;
end
end
% print according to the value of word
if flag == 1
disp(word);
else
disp('Sorry!');
end
%{
output:
Enter a word: ayush
Enter a letter: v
Sorry!
%}
Get Answers For Free
Most questions answered within 1 hours.