How to resolve the algorithm Even or odd step by step in the Action! programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Even or odd step by step in the Action! programming language

Table of Contents

Problem Statement

Test whether an integer is even or odd. There is more than one way to solve this task:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Even or odd step by step in the Action! programming language

Source code in the action! programming language

PROC OddByAnd(INT v)
  IF (v&1)=0 THEN
    Print(" even")
  ELSE
    Print(" odd ")
  FI
RETURN

PROC OddByMod(INT v)
  ;MOD doesn't work properly for negative numbers in Action!
  IF v<0 THEN
    v=-v
  FI
  IF v MOD 2=0 THEN
    Print(" even")
  ELSE
    Print(" odd ")
  FI
RETURN

PROC OddByDiv(INT v)
  INT d
  d=(v/2)*2
  IF v=d THEN
    Print(" even")
  ELSE
    Print(" odd ")
  FI
RETURN

PROC Main()
  INT i

  FOR i=-4 TO 4
  DO
    PrintF("%I is",i)
    OddByAnd(i)
    OddByMod(i)
    OddByDiv(i)
    PutE()
  OD
RETURN

  

You may also check:How to resolve the algorithm Statistics/Normal distribution step by step in the VBA programming language
You may also check:How to resolve the algorithm Entropy step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Knuth shuffle step by step in the Factor programming language
You may also check:How to resolve the algorithm Sort three variables step by step in the REXX programming language
You may also check:How to resolve the algorithm Sum of elements below main diagonal of matrix step by step in the BQN programming language