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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started