Top
Back: Parameters
Forward: Cyclic roots
FastBack: Examples
FastForward: Computing Groebner and Standard Bases
Up: Programming
Top: Singular Manual
Contents: Table of Contents
Index: Index
About: About this document

A.1.6 Formatting output

We show how to insert the result of a computation inside a text by using strings. First we compute the powers of 2 and comment the result with some text. Then we do the same and give the output a nice format by computing and adding appropriate space.

 
  // The powers of 2:
  int  n;
  for (n = 2; n <= 128; n = n * 2)
  {"n = " + string (n);}
==> n = 2
==> n = 4
==> n = 8
==> n = 16
==> n = 32
==> n = 64
==> n = 128
  // The powers of 2 in a nice format
  int j;
  string space = "";
  for (n = 2; n <= 128; n = n * 2)
  {
    space = "";
    for (j = 1; j <= 5 - size (string (n)); j = j+1)
    { space = space + " "; }
    "n =" + space + string (n);
  }
==> n =    2
==> n =    4
==> n =    8
==> n =   16
==> n =   32
==> n =   64
==> n =  128


Top Back: Parameters Forward: Cyclic roots FastBack: Examples FastForward: Computing Groebner and Standard Bases Up: Programming Top: Singular Manual Contents: Table of Contents Index: Index About: About this document
            User manual for Singular version 4-0-3, 2016, generated by texi2html.