Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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
Advertisements
