Preview:
#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;
}
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter