Find Total Number of Non-Empty Substrings of A String With N Characters. Here We Use The Word Proper Because We Do Not Consider String Itself As Part of Output

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

Input : abcd

Output : a
b
c
d
ab
bc
cd
abc
bcd
abcd

// Function to print all sub strings


void subString(char str[], int n)
{
// Pick starting point
for (int len = 1; len <= n; len++)
{
// Pick ending point
for (int i = 0; i <= n - len; i++)
{
// Print characters from current
// starting point to current ending
// point.
int j = i + len - 1;
for (int k = i; k <= j; k++)
cout << str[k];

cout << endl;


}
}
}

// Driver program to test above function


int main()
{
char str[] = "abc";
subString(str, strlen(str));
return 0;
}

You might also like