Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions