Skip to main content

Combination of two strings using array || combination of strings without repetition || combination of strings



       COMBINATION OF TWO STRINGS USING ARRAY







/*
​ * C Program to 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[50],  str2[50], str3[100][100], str4[100][100];
​    char str5[200][200], temp[200], str[200][200];
​    int i, 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 (i = 0;str1[i] != '\0';i++)
​    {
​        if (str1[i] =  = ' ')
​        {
​            str3[j][k] = '\0';
​            j++;
​            k = 0;
​        }
​        else
​        {
​            str3[j][k] = str1[i];
​            k++;
​        }
​        str3[j][k] = '\0'; 
​    }
​    k = 0;

​    for (i = 0;str2[i] != '\0';i++)
​    {
​        if (str2[i] == ' ')
​        {
​            str4[l][k] = '\0';
​            l++;
​            k = 0;
​        }
​        else
​        {
​            str4[l][k] = str2[i];
​            k++;
​        }
​        str4[l][k] = '\0';
​    }
​/* Code to make the first string words combination with second */
​    for (i = 0;i <= j;i++)
​    {
​        for (m = 0;m <= l;m++)
​        {
​            strcpy(temp, str3[i]);
​            strcat(temp, str4[m]);
​            strcpy(str5[index], temp);
​            index++;
​        }
​    } 
​ 
​/* Code to make the second string words combination with first */
​    for (i = 0;i <= l;i++)
​    {
​        for (m = 0;m <= j;m++)
​        {
​            strcpy(temp, str4[m]);
​            strcat(temp, str3[i]);
​            strcpy(str5[index], temp);
​            index++;
​        }
​    }

​/* Code to remove the repetitions */
​    for (i = 0;i <= index;i++)
​    {
​        for (j = i + 1;j <= index;j++)
​        {
​            if ((strcmp(str5[i], str5[j]) == 0)
​            {
​                for (k = j;k <= index;k++)
​                {
​                    strcpy(str5[k], str5[k + 1]);
​                }
​                index--;
​            }
​        }
​    }
​    for (i = 0;i <= index;i++)
​    { ++n;
​        printf("%d. %s\n", n,str5[i]);
​    }
​}



                              REGARDS,
                             ITKNOWLEDGE

Comments

Popular posts from this blog

ASCII TABLE || HEXADECIMAL TABLE

ASCII & Hexadecimal Table (CLICK THE IMAGE TO VIEW IT PROPERLY) REGARDS, ITK

INSTALLING TURBO C/C++ IN WINDOWS || INSTALLING TURBO C++ || INSTALLING BORLAND'S TURBO C++

Borland's Turbo C/C++ has been making the novices to know the power of coding with interest beside of being outdated since 1987. It was noted for its integrated development environment, small size, fast compile speed, comprehensive manuals and low price availability. But now it's completely free to download and use. You can download Turbo C/C++ of Borland's (according to your PC's requirements) by clicking here. TO SEE THE INSTALLATION VIDEO CLICK HERE . After the download is completed, follow the following steps (picture-wise too) after opening it : 1. Double click the application to start installation. 2. Now click next. 3. Accept the license aggreement to continue to install by clicking intsall button. 4. The installing page will look like - 5. After the installation is completed soon, click read me if you wish to see its license aggreement. 6. Otherwise you can continue by clicking finish. 7. Now go to the desktop and search ...

KEYBOARD CHARACTERS || KEYBOARD CHARACTER NAMES || KEYBOARD SYMBOLS AND THEIR USES || KEYBOARD CHARACTERS NAMES

The symbols used in keyboards are generally not known to all of us about. Many of us don't know either their use or their names what they are called as too. Here is the list of the symbols that are in the computer keyboards with their names. Symbols in Keyboards and their names Sl.   No.                    Symbol                                  Name 1                      & ampersand or and 2                        ‘ apostrophe or single quote 3               ...