Artificial Intelligence
Practical
Name: Ayush Singh
Course: B.Sc(hons) Computer Science
University Roll no. : 21013570021
Session: 2021-2024
Q1. Write a prolog program to calculate the sum of two numbers.
Code :
Output :
Q2. Write a Prolog program to implement max(X, Y, M) so that M is the
maximum of two numbers X and Y.
Code:
Output:
Q3. Write a program in PROLOG to implement factorial (N, F) where F
represents the factorial of a number N.
Code:
Output:
Q4. Write a program in PROLOG to implement generate_fib(N,T)
where T represents the Nth term of the fibonacci series.
Code:
Output:
Q5. Write a Prolog program to implement GCD of two numbers.
Code:
Output:
Q6. Write a Prolog program to implement power (Num,Pow, Ans) :
where Num is raised to the power Pow to get Ans.
Code:
Output:
Q7. Prolog program to implement multi (N1, N2, R) : where N1 and N2
denotes the numbers to be multiplied and R represents the result.
Code:
Output :
Q8. Write a Prolog program to implement memb(X, L): to check
whether X is a member of L or not.
Code:
Output:
Q9. Write a Prolog program to implement conc (L1, L2, L3) where L2 is
the list to be appended with L1 to get the resulting list L3.
Code:
Output:
Q10. Write a Prolog program to implement reverse (L, R) where List L
is original and List R is reversed list.
Code:
Output:
Q11. Write a program in PROLOG to implement palindrome (L) which
checks whether a list L is a palindrome or not.
Code:
Output:
Q12. Write a Prolog program to implement sumlist(L, S) so that S is
the sum of a given list L.
Code:
Output:
Q13. Write a Prolog program to implement two predicates
evenlength(List) and oddlength(List) so that they are true if their
argument is a list of even or odd length respectively.
Code:
Output:
Q14.Write a Prolog program to implement nth_element (N, L, X) where
N is the desired position, L is a list and X represents the Nth element
of L.
Code:
Output:
Q15. Write a Prolog program to implement maxlist(L, M) so that M is
the maximum number in the list.
Code:
Output:
Q16. Write a prolog program to implement insert_nth (I, N, L, R) that
inserts an item I into the Nth position of list L to generate a list R.
Code:
Output:
Q17. Write a Prolog program to implement delete_nth (N, L, R) that
removes the element on Nth position from a list L to generate a list R.
Code:
Output:
Q18. Write a program in PROLOG to implement merge (L1, L2, L3)
where L1 is first ordered list and L2 is second ordered list and L3
represents the merged list.
Code:
Output: