Prolog program for login without and with recursion. - Artificial intelligence

No comments
  •   Logon example without recursion.
Program


go:-
    write("Enter user name and password\n"),
    readln(User),
    readln(Pass),
    login(User,Pass);
    write("Login sucessful\n").
go:-
    write("Login sucessful\n").
login(dharmik,123).
login(nihar,456).

Output

?- go().
Enter user name and password
|: dharmik
|: 123
Login sucessful
true.

  • Logon example with recursion.

Program

go:-
    write("Enter user name and password\n"),
    readln(User),
    readln(Pass),
    login(User,Pass),
    write("Login sucessful\n").
go:-
    write("Login unsucessful\n"),
    go.
login(dharmik,123).
login(nihar,456).

Output

?- go().
Enter user name and password
|: dharmik
|: 456
Login unsucessful
Enter user name and password
|: dharmik
|: 123
Login sucessful
true

No comments :

Post a Comment