C program to check Subsequence, don’t confuse subsequence with substring. In our program we check if a string is a subsequence of another string. User will input two strings and we find if one of the strings is a subsequence of other. Program prints yes if either first string is a subsequence of second or second is a subsequence of first. We pass smaller length string first because our function assumes first string is of smaller or equal length than the second string.
[ad type=”banner”]C programming code
Output of program:
Input first string computer science is awesome Input second string tree YES[ad type=”banner”]
The logic of function is simple we keep on comparing characters of two strings, if mismatch occur then we move to next character of second string and if characters match indexes of both strings is increased by one and so on. If the first string ends then it is a subsequence otherwise not.