This C Program Find all possible subsets of given length in string.
Here is source code of the C Program to Find all possible subsets of given length in string. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
/*
* C Program to Find All Possible Subsets of given Length in String
*/
#include <stdio.h>
#include <string.h>
char a[20];
int n, len, j;
void main()
{
int i, index = 0, start = 0;
printf("Enter the string\n");
scanf("%s", a);
n = strlen(a);
printf("enter input length\n");
scanf("%d", &len);
printf("The subsets are\n");
for (i = 1;i < = n;i++)
{
if (index - start + 1 == i)
{
if (i == len)
{
for (j = index;j < n;j++)
{
for (i = start;i < index;i++)
printf("%c", a[i]);
printf("%c\n", a[j]);
}
if (start != i)
{
start++;
index = start;
}
}
else
{
index++;
}
}
}
}
$ cc string20.c $ a.out Enter the string programming enter input length 2 The subsets are pr po pg pr pa pm pm pi pn pg enter the string programming enter input length 4 The subsets are prog pror proa prom prom proi pron prog
Sanfoundry Global Education & Learning Series – 1000 C Programs.
advertisement
advertisement
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
If you wish to look at programming examples on all topics, go to C Programming Examples.
Next Steps:
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
Related Posts:
- Practice BCA MCQs
- Buy Computer Science Books
- Practice Computer Science MCQs
- Watch Advanced C Programming Videos
- Buy C Books