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.
If you find any mistake above, kindly email to [email protected]Related Posts:
- Practice BCA MCQs
- Apply for Computer Science Internship
- Apply for C Internship
- Check Computer Science Books
- Check C Books