//Function to find the Cartesian product of two strings:

PHOTO EMBED

Tue May 07 2024 15:13:22 GMT+0000 (Coordinated Universal Time)

Saved by @vedanti

#include <stdio.h>

void cartesian_product(char *str1, char *str2) {
    while (*str1 != '\0') {
        char *temp = str2;
        while (*temp != '\0') {
            printf("%c%c ", *str1, *temp);
            temp++;
        }
        str1++;
    }
    printf("\n");
}

int main() {
    char string1[] = "abc";
    char string2[] = "ab";
    printf("Cartesian product of '%s' and '%s': ", string1, string2);
    cartesian_product(string1, string2);
    return 0;
}
content_copyCOPY