Write a Prolog program to print out a square of n*n given characters on the screen. Call your predicate square/2. The first argument should be a (positive) integer. the second argument the character (any Prolog term) to be printed. Example:
?-square(5, '*').
*****
*****
*****
*****
*****
Yes
I just start to learn this language. I did this:
square(_,'_').
square(N, 'B') :-
N>0,
write(N*'B').
It doesn't work at all. Can anyone help me?
?- write_one('c').
will printc
. Can you write this predicate? – Will Nesswrite(N*'B')
is asking Prolog to write out the expressionN*'B'
. Prolog does not evaluate arithmetic expressions outsideis/2
expressions, and besides that there is no facility to create atoms through repetition of other atoms this way. Try harder. You can do it, you just have to be very explicit. – Daniel Lyons