Prolog program to find the square root of given number. - Artificial intelligence

No comments

  • Program to find the square root of given number.

Program:

domains
    N=integer
    I=integer
predicates
    start
    sq1(N,I)
    sq2(N,I)
clauses
start:-
    write("Enter number="),
    readint(N),
    sq1(N,1).
    sq1(N,I):-
    (I*I)>=N,
    sq2(N,I).
    sq1(N,I):-
    I1=I+1,
    sq1(N,I1).
    sq2(N,I):-
    (I*I)>N,
    write("Enter square number!\n"),
    start.
    sq2(_,I):-
    write("square root is ",I),

    write("\n").

Output:

Goal: Start
Enter number=8
Enter square number!
Enter number=9
Square root is 3
Yes

Goal:

No comments :

Post a Comment