Logo 
Search:

Artificial Intelligence Articles

Submit Article
Home » Articles » Artificial Intelligence » ProLogRSS Feeds

Prolog program to print numbers from 1 to 25 and display output as shown in description

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

Write a program to print numbers from 1 to 25
For e.g. the output is as follows:

1
2
3 Buzz 3
4
5
6 Buzz 3
7 Buzz 7 and so on

Code for Prolog program to print numbers from 1 to 25 and display output as shown in description in Artificial Intelligence

predicates
    go
    buzz(integer)
    check(integer)
    buzz3(integer)
    buzz7(integer)
    
clauses

    go:-
        buzz(1).
        
    buzz(26).
    
    buzz(N):-
        write(N),
        check(N),
        NN=N+1,
        buzz(NN).
            
    check(N):-
        R=N mod 3,
        buzz3(R),
        P=N mod 7,
        buzz7(P),
        write("\n").
    
    buzz3(0):-
        write("  Buzz3").

    buzz3(X).    
    
    buzz7(0):-
        write("  Buzz7").
        
    buzz7(X).            


OUT PUT
=======

1
2
3   Buzz3
4
5
6   Buzz3
7   Buzz7
8
9   Buzz3
10
11
12  Buzz3
13
14  Buzz7
15  Buzz3
16
17
18  Buzz3
19
20
21  Buzz3  Buzz7
22
23
24  Buzz3
25

Yes
  
Share: 



Milind Mishra
Milind Mishra author of Prolog program to print numbers from 1 to 25 and display output as shown in description is from India.
 
View All Articles

 
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!