Prolog program whether a number is a Prime

  • Find a number is a Prime or not:
    predicates
    go
    prime(integer,real,integer)
    
    
    clauses
    
    go:-
    write("enter no="),
    readint(X),
    Y=sqrt(X),
    prime(X,Y,2).
    
    prime(_,B,C):-
    C>B,
    write("is prime"),nl.
    
    prime(A,B,C):-
    C<B,
    E=A mod C,
    E0,
    D=C+1,
    prime(A,B,D).
  • 3 thoughts on “Prolog program whether a number is a Prime

    Leave a Reply

    Please log in using one of these methods to post your comment:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out /  Change )

    Google photo

    You are commenting using your Google account. Log Out /  Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out /  Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out /  Change )

    Connecting to %s