Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to read two strings and then output the third string which is a concatanation of the both excluding reapiting characters

Posted By: Milind Mishra     Category: Artificial Intelligence     Views: 3531

Write a complete prolog program to read two strings and then
output the third string which is a concatanation of the both
excluding reapiting characters for Example. if abd and dea
two strings, the output string must be abde.

Code for Prolog program to read two strings and then output the third string which is a concatanation of the both excluding reapiting characters in Artificial Intelligence

predicates
    start
    comp_str(string,string,string)
    comp_char(string,string,char,string)
goal
    clearwindow,
    start.
clauses
    start:-
        write("Enter first string = "),
        readln(Str1),nl,
        write("Enter second string = "),
        readln(Str2),nl,
        comp_str(Str1,Str2,Str3).

    comp_str(Str1,Str2,Str3):-
        Str2 <> "",
        frontchar(Str2,Char2,Rest2),
        comp_char(Str1,Str1,Char2,Str3),
        comp_str(Str3,Rest2,Str4).
    
    comp_str(Str1,Str2,Str3):-
        write("concat string = ",Str1).
        
    comp_char(Str1,TempStr1,Char2,Str3):-
        TempStr1 <> "",
        frontchar(TempStr1,Char1,Rest1),
        Char1 <> Char2,
        comp_char(Str1,Rest1,Char2,Str3).

    comp_char(Str1,TempStr1,Char2,Str3):-
        TempStr1 <> "",
        Str3 = Str1.

    comp_char(Str1,TempStr1,Char2,Str3):-
        str_char(Str2,Char2),
        concat(Str1,Str2,Str3).
        
        
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to read two strings and then output the third string which is a concatanation of the both excluding reapiting characters is from India.
 
View All Articles

Related Articles and Code:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!