- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to print all substrings of a given string in C++
In this tutorial, we will be discussing a program to print all the substring of a given string.
For this we will be given with a string or an array of characters. Our task is to print all the substrings of that particular string.
Example
#include<bits/stdc++.h> using namespace std; //printing all the substrings void print_substr(char str[], int n){ for (int len = 1; len <= n; len++){ for (int i = 0; i <= n - len; i++){ int j = i + len - 1; for (int k = i; k <= j; k++) cout << str[k]; cout << endl; } } } int main(){ char str[] = "abca"; print_substr(str, strlen(str)); return 0; }
Output
a b c a ab bc ca abc bca abca
- Related Articles
- C Program to print all permutations of a given string
- C# Program to find all substrings in a string
- How to List all Substrings in a given String using C#?
- Python Program to print all permutations of a given string
- Count Unique Characters of All Substrings of a Given String in C++
- Program to find total sum of all substrings of a number given as string in Python
- Print all permutations of a given string
- Program to find out the substrings of given strings at given positions in a set of all possible substrings in python
- Program to print all palindromes in a given range in C++
- Find all substrings in a string using C#
- Print all distinct permutations of a given string with duplicates in C++
- C# program to print all distinct elements of a given integer array in C#
- Count the number of vowels occurring in all the substrings of given string in C++
- Program to find out number of distinct substrings in a given string in python
- Java Program to Print all unique words of a String

Advertisements