Tusohian

Factorial in Prolog

Jun 20th, 2019
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/I 0.21 KB | None | 0 0
  1. go:-
  2. write('Enter The Number: '),
  3. read(N),
  4. TEMP is 1,
  5. fact(N,TEMP).
  6.    
  7. fact(1,TEMP):-
  8. (
  9.     write('Factorial is: '),write(TEMP)
  10. ).
  11.  
  12. fact(N,TEMP):-
  13. (  
  14.     RESULT is TEMP*N,
  15.     B is N-1,
  16.     fact(B,RESULT)
  17. ).
Add Comment
Please, Sign In to add comment