How to resolve the algorithm Floyd's triangle step by step in the Action! programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Floyd's triangle step by step in the Action! programming language

Table of Contents

Problem Statement

Floyd's triangle   lists the natural numbers in a right triangle aligned to the left where

The first few lines of a Floyd triangle looks like this:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Floyd's triangle step by step in the Action! programming language

Source code in the action! programming language

PROC Triangle(BYTE level)
  INT v,i
  BYTE x,y
  BYTE ARRAY widths(20)
  CHAR ARRAY tmp(5)

  v=1
  FOR y=1 TO level-1
  DO
    v==+y
  OD
  FOR x=0 TO level-1
  DO
    StrI(v+x,tmp)
    widths(x)=tmp(0)
  OD

  v=1
  FOR y=1 TO level
  DO
    FOR x=0 TO y-1
    DO
      StrI(v,tmp)
      FOR i=tmp(0) TO widths(x)-1
      DO 
        Put(32)
      OD
      Print(tmp)
      IF x
        Put(32)
      ELSE
        PutE()
      FI
      v==+1
    OD
  OD
RETURN

PROC Main()
  BYTE LMARGIN=$52,oldLMARGIN

  oldLMARGIN=LMARGIN
  LMARGIN=0 ;remove left margin on the screen

  Put(125) PutE() ;clear the screen
  Triangle(5)
  PutE()
  Triangle(13)

  LMARGIN=oldLMARGIN ;restore left margin on the screen
RETURN

  

You may also check:How to resolve the algorithm Dynamic variable names step by step in the Go programming language
You may also check:How to resolve the algorithm Primality by trial division step by step in the Ada programming language
You may also check:How to resolve the algorithm EKG sequence convergence step by step in the Perl programming language
You may also check:How to resolve the algorithm Luhn test of credit card numbers step by step in the Haskell programming language
You may also check:How to resolve the algorithm 100 doors step by step in the EasyLang programming language