Check and print specific characters according to input

  • 0

    Within 20 mins, write a program to complete below task. Language not specified.

    Given positive integers A, B, and N, write a program that prints integers from 1 to N. But for integers that are multiples of A, print 'F', and for multiples of B, print 'B'. For integers which are multiples of both A and B, print 'FB'.

    Your program should read lines of text from standard input. Each line will contain A, B, and N as space-delimited positive integers.
    For each line of input, print to standard output a line of space-delimited integers 1 through N, replacing integers as described above.

    Input: 3 5 10
    Output: 1 2 F 4 B F 7 8 F B

    Input: 2 7 15
    Output: 1 F 3 F 5 F B F 9 F 11 F 13 FB 15

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.