Examples
Print primes number :
echo '2p3ps#s@s&ds.x'|dcAs an example of a relatively simple program in dc, this command (in 1 line):
dc -e 'psj]shsz PnP10Pdx]dx'will convert distances from metres to feet and inches; the bulk of it is concerned with prompting for input, printing output in a suitable format and looping round to convert another number.
As an example, here is an implementation of the Euclidean algorithm to find the GCD:
dc -e '??dsax+p' # shortest dc -e 'P?P?dsax+Pp' # easier-to-read versionComputing the factorial of an input value,
dc -e '?sQdsFxp'A more complex example performs Diffie-Hellman key exchange. This was popular as a signature block among cypherpunks during the ITAR debates:
#!/usr/bin/perl -- -export-a-crypto-system-sig Diffie-Hellman-2-lines ($g,$e,$m)=@ARGV,$m||die"$0 gen exp mod\n";print`echo "16dio1[d2%Sa2/d0Read more about this topic: Dc (computer Program)
Famous quotes containing the word examples:
“It is hardly to be believed how spiritual reflections when mixed with a little physics can hold peoples attention and give them a livelier idea of God than do the often ill-applied examples of his wrath.”
—G.C. (Georg Christoph)
“Histories are more full of examples of the fidelity of dogs than of friends.”
—Alexander Pope (16881744)
“There are many examples of women that have excelled in learning, and even in war, but this is no reason we should bring em all up to Latin and Greek or else military discipline, instead of needle-work and housewifry.”
—Bernard Mandeville (16701733)