How to resolve the algorithm Binary digits step by step in the CLU programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Binary digits step by step in the CLU programming language

Table of Contents

Problem Statement

Create and display the sequence of binary digits for a given   non-negative integer. The results can be achieved using built-in radix functions within the language   (if these are available),   or alternatively a user defined function can be used. The output produced should consist just of the binary digits of each number followed by a   newline. There should be no other whitespace, radix or sign markers in the produced output, and leading zeros should not appear in the results.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Binary digits step by step in the CLU programming language

Source code in the clu programming language

binary = proc (n: int) returns (string)
    bin: string := ""
    while n > 0 do
        bin := string$c2s(char$i2c(48 + n // 2)) || bin
        n := n / 2
    end
    return(bin)
end binary

start_up = proc ()
    po: stream := stream$primary_output()
    tests: array[int] := array[int]$[5, 50, 9000]
    
    for test: int in array[int]$elements(tests) do
        stream$putl(po, int$unparse(test) || " -> " || binary(test))
    end
end start_up

  

You may also check:How to resolve the algorithm Letter frequency step by step in the Harbour programming language
You may also check:How to resolve the algorithm Return multiple values step by step in the Z80 Assembly programming language
You may also check:How to resolve the algorithm Bulls and cows step by step in the Rust programming language
You may also check:How to resolve the algorithm Egyptian division step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm Mouse position step by step in the Python programming language