'************************************************************ '* This small program finds coincidences of letters in * '* two given words * '* -------------------------------------------------------- * '* SAMPLE RUN: * '* * '* Input first word : Bonjour * '* Input second word: Monsieur * '* * '* The letter o is common to the two words. * '* The letter n is common to the two words. * '* The letter u is common to the two words. * '* The letter r is common to the two words. * '* * '* -------------------------------------------------------- * '* Reference: "Exercices en Turbo Pascal By Claude Delannoy * '* Eyrolles, 1997". * '* * '* Basic Release By J-P Moreau, Paris. * '* (www.jpmoreau.fr) * '************************************************************ 'Program Common_Letters DEFINT I-N 'mot1$, mot2$ 1st & 2nd words 'ifound 2 letters identical if TRUE 'i, j loop counters 'l1,l2 length of mot1, mot2 CLS ' Read two words PRINT INPUT " Input first word : ", mot1$ INPUT " Input second word: ", mot2$ PRINT l1 = LEN(mot1$) l2 = LEN(mot2$) ' Compare the two words FOR i = 1 TO l1 ifound = 0 j = 1 WHILE ifound = 0 AND j <= l2 IF MID$(mot1$, i, 1) = MID$(mot2$, j, 1) THEN PRINT " The letter "; MID$(mot1$, i, 1); " is common to the two words." mot2$ = MID$(mot2$, 1, j - 1) + " " + MID$(mot2$, j + 1, l2) 'to deactivate the found coincidence ifound = 1 END IF j = j + 1 WEND NEXT i PRINT END 'end of file comlet.bas