C Programming Code Examples C > Strings Code Examples Display Every Possible Combination of Two Words from the given 2 String without Displaying Repeated Combinations Display Every Possible Combination of Two Words from the given 2 String without Displaying Repeated Combinations #include <stdio.h> #include <string.h> void main() { char str1[80], str2[80], str3[160][160], str4[160][160]; char str5[320][320], temp[320], str[320][320]; int x, j = 0, k = 0, l = 0, m = 0, index = 0, n = 0; printf("Enter first string\n"); scanf("%[^\n]s", str1); printf("Enter second string\n"); scanf(" %[^\n]s", str2); /* code to convert string in 2-D array */ for (x = 0;str1[x] != '\0';x++) { if ((str1[x] = = ' ') { str3[j][k] = '\0'; j++; k = 0; } else { str3[j][k] = str1[x]; k++; } str3[j][k] = '\0'; } k = 0; for (x = 0;str2[x] != '\0';x++) { if ((str2[x] == ' ') { str4[l][k] = '\0'; l++; k = 0; } else { str4[l][k] = str2[x]; k++; } str4[l][k] = '\0'; } /* Code to make the first string words combination with second */ for (x = 0;x <= j;x++) { for (m = 0;m <= l;m++) { strcpy(temp, str3[x]); strcat(temp, str4[m]); strcpy(str5[index], temp); index++; } } /* Code to make the second string words combination with first */ for (x = 0;x <= l;x++) { for (m = 0;m <= j;m++) { strcpy(temp, str4[m]); strcat(temp, str3[x]); strcpy(str5[index], temp); index++; } } /* Code to remove the repetitions */ for (x = 0;x <= index;x++) { for (j = x + 1;j <= index;j++) { if ((strcmp(str5[x], str5[j]) == 0) { for (k = j;k <= index;k++) { strcpy(str5[k], str5[k + 1]); } index--; } } } for (x = 0;x <= index;x++) { printf("%s\n", str5[x]); } }