dc command in Linux with examples
dc command in Linux is used to evaluate arithmetic expressions. It evaluates expressions in the form of a postfix expression. Entering a number pushes it into the stack and entering an operator evaluates an expression and pushes the result back into the stack. It can evalute +, -, /, *, %, ^. Different commands can be used to manipulate stack.
Syntax:
dc [OPTION] [file ...]
Below table illustrate the different commands and their explanation:
| Command | Operation |
|---|---|
| p | Prints the value on the top of the stack and ends the statement with a newline. |
| n | Prints the value on the top of the stack and ends the line with a null statement. |
| f | Prints the entire stack, without any alteration. |
| P | Pops the value from the top of the stack. |
| c | Clear the stack. |
| d | Duplicates the top value and push it into the main stack. |
| r | Reverses the order of top two elements in the stack. |
| Z | Pops the value from the stack, calculate the number of digits in it and pushes that number. |
| X | Pops the value from the stack, calculate the number of fraction digits in it and pushes that number. |
| z | Pushes the stack length into the stack. |
| i | Pops the value from the stack and uses it as input radix. |
| o | Pops the value from the stack and uses it as output radix. |
| k | Pops the values from the stack and uses it to set precision. |
| I | Pushes the value of input radix into the stack. |
| O | Pushes the value of output radix into tje stack |
| K | Pushes the precission value into the stack. |
Example 1:

Example 2:

Note: In second example, the output changes because we changed the output-radix.
Options:
- expression : This command is used to evaluate a particular expression.
- file : This command is used to evalute the contents of the file.
- help : This command displays help information.
- version: This command is used to display version information.
Recommended Posts:
- yes command in Linux with Examples
- gdb command in Linux with examples
- man command in Linux with Examples
- arp command in Linux with examples
- cmp Command in Linux with examples
- bg command in Linux with Examples
- w command in Linux with Examples
- more command in Linux with Examples
- fg command in Linux with examples
- mv command in Linux with examples
- cal command in Linux with Examples
- gs command in Linux with Examples
- cut command in Linux with examples
- col command in Linux with Examples
- id command in Linux with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



