Ask Question
28 February, 06:23

5. Write a program to remove any duplicate letters from a word and display the new word maintaining the original order. For example, bananas would become bans and bookkeeper would become bokepr. You may not use any special unique commands!

+2
Answers (1)
  1. 28 February, 06:53
    0
    word = input ('Enter a single word: ', 's');

    n = length (word);

    nodupWord = [];

    for i = 1:n

    dup = false;

    c = word (i);

    for j = 1:i-1

    if word (j) = = c

    dup = true;

    break;

    end

    end

    if ~dup

    nodupWord = [nodupWord, c]; %add the non-duplicate char to end

    end

    end

    disp (['Adjusted word: ', nodupWord])

    Explanation:

    The code is in Python.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “5. Write a program to remove any duplicate letters from a word and display the new word maintaining the original order. For example, ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers