An open API service indexing awesome lists of open source software.

https://github.com/zikiflicky/calculator

A small and simple calculator written in C
https://github.com/zikiflicky/calculator

c c99 calculator

Last synced: about 1 month ago
JSON representation

A small and simple calculator written in C

Awesome Lists containing this project

README

          

# Calculator
This is a simple command line calculator program written in C (C99).

It can also be used as a library, if one imports just `calculator.c` and `calculator.h`.

It currently supports basic operators like + - * / () % ^.

This program was created because I wanted to think of an algorithm to do calculations, so I tried to think of my own one and came up with this.

## Build instructions
First, `git clone` the repository
### Linux or any other unix-like operating systems
#### Dependencies
* GNU make
* GCC
#### Instructions
* `cd` into the program's directory.
* Type `make`.
* Type `./calculator` to run the program

### Windows
#### Dependencies
* Visual Studio 2019
#### Instructions
* `cd` into the program's directory.
* Type `.\make`.
* Type `.\calculator` to run the program

## How it works
This calculator works by moving linearly on an array of tokens and creating a tree of nodes, that are later recursively evaluated, and at the end return a number.

### This is a node tree created from 1+2*3^4-5
```
(-)
/ \
(+) (5)
/ \
(1) (*)
/ \
(2) (^)
/ \
(3) (4)
```
It will later be evaluated recursivaly to finally return 158.