Basic Operations
To multiply four and five in dc (note that most of the whitespace is optional):
4 5 * pNotes: save it in a file, such as cal.txt, and run the command: dc cal.txt, you will see the result. Click "q" can exist from dc. You can also get the result by below command:
echo "4 5 * p" |dcThis translates into "push four and five onto the stack, then, with the multiplication operator, pop two elements from the stack, multiply them and push the result back on the stack." Then the 'p' command is used to examine (print out to the screen) the top element on the stack.
The arithmetic precision is changed with the command 'k', which sets the number of fractional digits (the number of digits following the point) to be used for arithmetic operations. Since the default precision is zero, this sequence of commands produces '0' as a result:
2 3 / pBy adjusting the precision with 'k', arbitrary number of decimal places can be produced. This command sequence outputs '.66666'.
5 k 2 3 / pTo evaluate : ('v' computes the square root of the top of the stack and '_' is used to input a negative number):
12 _3 4 ^ + 11 / v 22 - pTo swap the top two elements of the stack, use the 'r' command. To duplicate the top element, use the 'd' command.
Read more about this topic: Dc (computer Program)
Famous quotes containing the words basic and/or operations:
“We cant nourish our children if we dont nourish ourselves.... Parents who manage to stay married, sane, and connected to each other share one basic characteristic: The ability to protect even small amounts of time together no matter what else is going on in their lives.”
—Ron Taffel (20th century)
“It may seem strange that any road through such a wilderness should be passable, even in winter, when the snow is three or four feet deep, but at that season, wherever lumbering operations are actively carried on, teams are continually passing on the single track, and it becomes as smooth almost as a railway.”
—Henry David Thoreau (18171862)