Question: Define an ocaml function, called print_alternating, that takes three inputs: one, two, and num. One and two can be any double-quoted strings of text (e.g.,

Define an ocaml function, called print_alternating, that takes three inputs: one, two, and num. One and two can be any double-quoted strings of text (e.g., "X" or "abc"); num should be a non-negative integer. This function should print a pattern of NUM items, alternating between the strings ONE and TWO, with blank spaces in between, as illustrated below:

# print_alternating "X" "_" 5;; X _ X _ X - : unit = () # print_alternating "abc" "$$" 7;; abc $$ abc $$ abc $$ abc - : unit = ()

Hint: Recall that an expression such as Printf.printf "%s " "abc" will cause abc to be printed out, followed by a blank space.

Hint: The first time through, print ONE; then, for the recursive function call, swap the positions of ONE and TWO.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!