A multithreaded calculator application written in C that demonstrates the use of threads and parallelism to perform mathematical operations like addition, multiplication, factorials, and more.
- Addition: Parallel addition of numbers using multiple threads.
- Multiplication: Parallel multiplication of numbers.
- Factorial Calculation: Calculate the factorial of numbers in parallel.
- Average Calculation: Compute the average of numbers.
- Dynamic Input: Add numbers to the list during runtime.
- C Compiler: GCC or any C99-compliant compiler.
- CMake: Version 3.10 or higher.
- POSIX Threads: Required for multithreading.
pthread
: Used for multithreading.
To install required libraries on a Debian-based system (e.g., Ubuntu), use the following command:
sudo apt-get install libpthread-stubs0-dev
For RedHat-based systems (e.g., CentOS, Fedora), you can use:
sudo yum install glibc-devel
git clone /~https://github.com/yourusername/MultiThreadCalculator.git
cd MultiThreadCalculator
mkdir build
cd build
cmake ..
make
./bin/MultiThreadCalculator <thread_count>
- Replace
<thread_count>
with the number of threads you want to use. For example:
./bin/MultiThreadCalculator 4
The program will prompt you to:
- Enter the number of elements.
- Enter the numbers.
- Choose operations (e.g., addition, multiplication, etc.).
./bin/MultiThreadCalculator 4
Input:
Enter the number of elements: 3
Enter the numbers:
Number 1: 2
Number 2: 4
Number 3: 6
Choose operation:
1. Add Numbers
2. Multiply Numbers
3. Calculate Factorial of Numbers
4. Calculate Average
5. Add a Number
6. Exit
Output:
The sum is: 12.00
The product is: 48.00