printing - How to print square of n*n given characters in prolog? -


write prolog program print out square of n*n given characters on screen. call predicate square/2. first argument should (positive) integer. second argument character (any prolog term) printed. example:

?-square(5, '*'). ***** ***** ***** ***** ***** yes 

i start learn language. did this:

square(_,'_'). square(n, 'b') :-         n>0,         write(n*'b'). 

it doesn't work @ all. can me?

so question is, basically, "how write loop nested in loop?"

this how write empty loop integer counter:

loop(0). loop(n) :- n > 0, n0 n-1, loop(n0). 

which in c be:

for(i=0; < n; ++i) { } 

and seem know how print (write(foo)).


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -