Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//This is a C program that generates all palindrome decombinations #include<stdi

ID: 3687118 • Letter: #

Question

//This is a C program that generates all palindrome decombinations

#include<stdio.h>
#include<string.h>

void check(char *a, int index, int max, int len) {
   int i, j;
   int last, first, count, flag = 0;

   if (max == 1) {
       printf("%c ", a[index]);
   }
   else {
       for (i = 0; i < max; i++) {
           first = index;
           last = index + max - 1;

           while (last > first) {
               if (a[first] != a[last]) {
                   flag = 1;
                   break;
               }
               last--;
               first++;
           }
           if (flag == 0) {
               for (i = 0; i < index; i++) {
                   printf("%c ", a[i]);
               }
               for (i = 0; i < max; i++) {
                   printf("%c", a[index + i]);
               }

               for (i = index + max; i < len; i++) {
                   printf(" %c", a[i]);
               }
               printf(" ");
           }
       }
   }
}

int test(char a[]) {
   int index = 0, strcount = 1;
   int len = strlen(a);
   a[len] = '';

   while (strcount <= len) {
       while (index < len) {
           check(a, index, strcount, len);
           index++;
       }
       if (strcount == 1) {
           printf(" ");
       }
       index = 0;
       strcount++;
   }
   return 0;
}

int main() {

  char str[] = "xyxxyx";
   test(str);
}

OUTPUT:
x y x x y x
x y xx y x
xyx x y x
x y x xyx
x yxxy x
xyxxyx

One of the outputs that are missing in this example is "xyx xyx" which is a program error that I am trying to fix that seems to appear whenever the palindromes are of equal lengths. Any help would be appreciated.

Explanation / Answer

in this program you have to give space after index 2. it might be fix your problem.