Question:
Write recursive functions that list all of the one-element, two-element, and three-element subsets of a given?
Dr_Natas
2013-04-03 12:38:40 UTC
I'm not able to display the 3 element
e.g.
three_ele_subs ("ACEG")
{A, C, E}
{A, C, G}
{A, E, G}
{C, E, G}

#include
#include
#define CMP_LEN 100

int is_empty (const char *) ; /* Checks if set is empty */
char *two_ele_subs(char *, int, int); /* Lists two-element subsets of a given set of letters */
void print_with_commas(const char *); /* Prints commas that separate each character in a set */
void print_set(const char *) ;
char *one_ele_subs(char *set, int char_count1);
char *tree_ele_subs(char *set, int char_count1, int char_count2, int char_count3);


int main(void)
{
/* Declare variables */
int c_count1 = 0 ; /* Counts the first character in the subset */
int c_count2 = 1 ; /* Counts the second character in the subset */
int c_count3 = 2 ;
char compound[CMP_LEN]; /* string representing a compound */

printf("Enter at least 4 letters with no space e.g. 'abcd'\n");
scanf ("%s", compound);

/* Provide one-element subsets of a given set of letters */
printf("\nNow demonstrating one-element subsets of a set of letters.\n");
printf("One element\n");
one_ele_subs(compound, c_count1);

printf("\nNow demonstrating two-element subsets of a set of letters.\n");
printf("Two element\n");
two_ele_subs(compound, c_count1, c_count2);

/* Provide tree-element subsets of a given set of letters */
printf("\nNow demonstrating tree-element subsets of a set of letters.\n");
printf("Tree element\n");
tree_ele_subs(compound, c_count1, c_count2, c_count3);

return 0;
}

int is_empty(const char *set)
{
/* Return null character if set is empty */
return (set[0] == '\0');
}


char *one_ele_subs(char *set, int char_count1)
{
char sub[65]; /* The subset of a given set of letters */

int i = 0;

/* Check if set is empty */
if (is_empty(set))
{
printf("\nThere is no set for testing.");
}
else
{
/* Copy characters into subset provided that limits have not been reached */
if (char_count1 < strlen(set) - 1)
{
for (i = 0; i < strlen(set); i++)
{
strncpy(&sub[0], &set[char_count1], 1);
sub[strlen(set) - 2] = '\0';
print_set(sub);
printf("\n");
char_count1++;

}
printf("\n");
}
}
}

char *two_ele_subs(char *set, int char_count1, int char_count2)
{
char sub[65]; /* The subset of a given set of letters */

/* Check if set is empty */
if (is_empty(set))
printf("\nThere is no set for testing.");
else
{
/* Copy characters into subset provided that limits have not been reached */
if (char_count1 < strlen(set) - 1)
{
if (char_count2 < strlen(set))
{
strncpy(&sub[0], &set[char_count1], 1);
strncpy(&sub[1], &set[char_count2], 1);
sub[strlen(set) - 2] = '\0';
print_set(sub);
printf("\n");

/* Adjust counter and call function again */
two_ele_subs(set, char_count1, char_count2 + 1);
}
else
{
/* Reset counter for char_count2 to help prepare for next copy batch */
char_count2 = char_count1 + 2;
/* Adjust counter and call function again */
two_ele_subs(set, char_count1 + 1, char_count2);
}
}
}
}


char *tree_ele_subs(char *set, int char_count1, int char_count2, int char_count3)
{
char sub[65]; /* The subset of a given set of letters */

/* Check if set is empty */
if (is_empty(set))
{
printf("\nThere is no set for testing.");
}
else
{
/* Copy characters into subset provided that limits have not been reached */
if (char_count1 < strlen(set) - 1)
{
if (char_count1 < strlen(set))
{
strncpy(&sub[0], &set[char_count1],
Three answers:
anonymous
2013-04-07 02:34:11 UTC
To do this the code would have to be extended by a lot, so it is best to shorten the code so the recursive functions can be written.
suzette
2016-04-17 18:27:58 UTC
If you want to start off producing a work from landscaping, or just don’t know how to begin producing your dream landscape or what equipment and resources to use then is the tie for this manual https://tr.im/bkHyW , the manual Ideas 4 Landscaping simply because the tips from an seasoned person is always welcome.

Idea 4 Landscaping is a guidebook with, even if you have no knowledge what so ever, you can adjust a backyard, a frontward or a backyard from zero to ideal, best due to the fact is just like you want it.

Ideas 4Llandscaping it will only place the tips so that you can make your dream come to daily life.
?
2016-10-25 15:10:57 UTC
i have no longer had a lot sleep so i am going to offer a short commentary for now. Then later, if available, i am going to write extra... 2 issues leap out at me. i'd re-examine each and every thing and ask your self if someone that has no understanding of the martial arts will be able to adhere to you and understand what you're saying? My different remark is that you element out 4 factors of combating. i'm no longer positive that is the way i'd describe it. all of us use our own terminology and what we are conscious of. In my analyze we basically say that for any combating gadget/variety to be nicely rounded, it ought to teach the thanks to cope with combating in any respect 4 ranges of unarmed strive against. We outline those 4 ranges as: Kicking determination, Punching determination, Trapping determination, and Grappling determination. at the same time as many others have their own names for those they're relating a similar concepts as ours. some can actually have extra or fewer counting on how they wreck combating down. The 4 ranges we use cover something an unarmed attacker can do from kicking determination (the longest distance from you), to body to body contact. It also covers each and every thing in between. some issues may really overlap into better than one determination. My basically challenge such as your terminology is that Chin-Na isn't appreciably nicely-known even contained in the martial arts international. in my opinion i'd be susceptible to apply a extra elementary time period or words. then you definitely do not ought to grant a proof of Chin-Na. basically my concepts.... ...


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...