]> www.ginac.de Git - cln.git/blobdiff - examples/nextprime.cc
Initial revision
[cln.git] / examples / nextprime.cc
diff --git a/examples/nextprime.cc b/examples/nextprime.cc
new file mode 100644 (file)
index 0000000..2559eed
--- /dev/null
@@ -0,0 +1,25 @@
+// This program prints the smallest probable prime >= x, x being given on the
+// command line.
+
+// We work with real numbers and integers.
+#include <cl_real.h>
+#include <cl_integer.h>
+
+// We do I/O.
+#include <cl_io.h>
+#include <cl_integer_io.h>
+
+// The function nextprobprime() is part of the number theory package.
+#include <cl_numtheory.h>
+
+int main (int argc, char* argv[])
+{
+       if (argc != 2) {
+               fprint(cl_stderr, "Usage: nextprime x\n");
+               exit(1);
+       }
+       cl_R x = (cl_R)argv[1];
+       cl_I p = nextprobprime(x);
+       fprint(cl_stdout, p);
+       fprint(cl_stdout, "\n");
+}