1. Home
  2. /
  3. Ada-spark
  4. /
  5. Swap Two Numbers

Swap Two Numbers - Ada-spark Typing CST Test

Loading…

Swap Two Numbers — Ada-spark Code

A SPARK Ada procedure that swaps the values of two integers using in-out parameters.

procedure Swap(A, B : in out Integer) is
	Temp : Integer;
begin
	Temp := A;
	A := B;
	B := Temp;
end Swap;

Ada-spark Language Guide

SPARK is a formally verifiable subset of the Ada programming language designed for high-integrity and safety-critical systems. It enforces strong typing, design-by-contract, and static analysis to mathematically prove program correctness and eliminate entire classes of bugs.

Primary Use Cases

  • ▸Avionics flight control software
  • ▸Railway signaling and interlocking
  • ▸Medical device firmware
  • ▸Cybersecure embedded systems
  • ▸Automotive safety ECUs

Notable Features

  • ▸Design-by-contract with pre/postconditions
  • ▸Strong static typing and modularization
  • ▸GNATprove formal verification
  • ▸Guaranteed absence of runtime errors (AoRTE)
  • ▸High-integrity code generation support

Origin & Creator

Developed by Praxis (now Altran UK) and later extended by AdaCore, leading vendors of Ada technology for mission- and safety-critical software.

Industrial Note

SPARK is used where DO-178C Level A or IEC 61508 SIL-4 compliance is required, enabling mathematical proof of correctness for safety-critical and security-critical applications.

More Ada-spark Typing Exercises

Hello World in SPARK AdaSafe Division with ContractsSum of Two NumbersFactorial FunctionCheck Even NumberArray SumMax of Two NumbersSimple Loop PrintCheck Prime Number

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher