How to resolve the algorithm N'th step by step in the CLU programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm N'th step by step in the CLU programming language

Table of Contents

Problem Statement

Write a function/method/subroutine/... that when given an integer greater than or equal to zero returns a string of the number followed by an apostrophe then the ordinal suffix.

Returns would include 1'st 2'nd 3'rd 11'th 111'th 1001'st 1012'th

Use your routine to show here the output for at least the following (inclusive) ranges of integer inputs: 0..25, 250..265, 1000..1025

Note: apostrophes are now optional to allow correct apostrophe-less English.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm N'th step by step in the CLU programming language

Source code in the clu programming language

nth = proc (n: int) returns (string)
    num: string := int$unparse(n)
    sfx: array[string] := array[string]$[0: "th", "st", "nd", "rd"]

    if n / 10 // 10 = 1 cor n // 10 > 3 then
        return(num || sfx[0])
    else
        return(num || sfx[n // 10])
    end
end nth

do_range = proc (from, to: int)
    po: stream := stream$primary_output()
    col: int := 0
    
    for i: int in int$from_to(from,to) do
        stream$putleft(po, nth(i), 7)
        col := col + 1
        if col = 10 then
            stream$putc(po, '\n')
            col := 0
        end
    end
    stream$putl(po, "\n")
end do_range 

start_up = proc ()
    do_range(0,25)
    do_range(250,265)
    do_range(1000,1025)
end start_up

  

You may also check:How to resolve the algorithm Magnanimous numbers step by step in the Ring programming language
You may also check:How to resolve the algorithm Find the missing permutation step by step in the Java programming language
You may also check:How to resolve the algorithm Handle a signal step by step in the Crystal programming language
You may also check:How to resolve the algorithm 2048 step by step in the BASIC programming language
You may also check:How to resolve the algorithm Grayscale image step by step in the Nim programming language