Pure Programmer
Blue Matrix


Cluster Map

Project: Aligning Floating Point with printf()

Write a program that demonstrates floating point formatting using default (most compact), fixed point and exponential formats using printf() and/or sprintf() style output. Print using no precision, precision of 2 and a field width of 10 with precision 2. Your program should reproduce the output shown using the following variables:

  • π = 3.141592653589793
  • 𝑒 = 2.718281828459045
  • avogadro = 6.0221412927e23
  • electron_mass = 9.1093821545e-31

Output
$ swiftc AligningFloatingPointWithPrintf.swift -I . -L . -lUtils error: link command failed with exit code 1 (use -v to see invocation) ld: library not found for -lUtils clang: error: linker command failed with exit code 1 (use -v to see invocation)

Solution