UNIVERSITY OF WEST ATTICA
SCHOOL OF ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING AND INFORMATICS
Computer Programming
Vasileios Evangelos Athanasiou
Student ID: 19390005
Supervisor: Georgios Meletiou, Laboratory Teaching Staff
Athens, December 2021
This project focuses on the implementation and documentation of independent subprograms (functions) in C to solve mathematical and logical problems using Menu options for users to choose. It specifically covers the calculation of trigonometric values using Taylor series and the recursive solution to the Towers of Hanoi game.
| Section | Folder / File | Description |
|---|---|---|
| 1 | assign/ |
Assignment material |
| 1.1 | assign/project5.png |
Assignment description / problem statement (English) |
| 1.2 | assign/εργασία5.png |
Assignment description / problem statement (Greek) |
| 2 | docs/ |
Theoretical documentation |
| 2.1 | docs/Subprograms.pdf |
Functions and subprograms in C (English) |
| 2.2 | docs/Υποπρογράμματα.pdf |
Functions and subprograms in C (Greek) |
| 3 | src/ |
Source code implementations |
| 3.1 | src/Hanoi.c |
Tower of Hanoi example using recursive function |
| 3.2 | src/Menu.c |
Menu-driven program demonstrating modular functions |
| 3.3 | src/SinCosTaylor.c |
Computing sine and cosine using Taylor series via functions |
| 4 | README.md |
Repository overview and instructions |
This program calculates the sine and cosine of an angle (in degrees) provided by the user.
It compares results from the standard math.h library with calculations from the infinite Taylor series.
-
Input Handling: Reads an angle
$\Omega$ in degrees and converts it to radians ($w$ ). -
Trigonometric Calculations:
-
Library Functions:
sin(w)andcos(w)frommath.h. -
Taylor Series: Implements infinite series for sine and cosine:
$$ \sin(x) = x - \frac{x^3}{3!} + \frac{x^5}{5!} - \frac{x^7}{7!} + \dots $$
-
-
Precision Check: Compares library and Taylor results using a minimal difference threshold (e.g.,
$0.0000009$ ).
stdio.h– Standard I/O (printf,scanf)math.h– Trigonometric functions and absolute value (fabs)#define pi 3.14159– Constant for degree-to-radian conversion
This program implements the Towers of Hanoi logic puzzle using recursion.
-
Disk Input: Prompts the user for the number of disks.
-
Move Calculation: Computes the minimum moves required:
$$ 2^n - 1 $$
-
Recursive Solution: Implements
Move_Disksto print the step-by-step movement of disks between posts A, B, and C.
| Function | Purpose |
|---|---|
Read_num_Disks() |
Reads the number of disks from the user |
Num_Min_Moves(int n) |
Computes the minimum move count for n disks |
Move_Disks(int n, char A, char B, char C) |
Recursively prints the movement path of disks |
The program implements a loop that repeatedly displays a menu until the user chooses to exit. It tracks the total number of valid operations performed during the session and prints this sum upon exiting.
The program is modular and uses independent subroutines for specific tasks:
Title(): Displays the program title and headers.Read_A()andRead_B(): Prompts the user to enter two integers, (A) and (B).Exit(): Handles termination of the menu loop and returns a count for the exit operation.
-
Power ((A^B))
-
Power(int, int): Calculates (A^B). -
Check_Power()andCheck_Valid_Power(): Validate and display results.
-
-
Factorial ((A!) and (B!))
-
Factorial(int): Computes factorial. -
Check_Factorial_A(),Check_Factorial_B(), andCheck_Factorial(): Validate inputs (e.g., negative numbers) and display results.
-
-
Combinations ((A) per (B))
-
Combinations(int, int): Calculates $$ \frac{A!}{B!(A-B)!} $$ -
Validates that (A > B) and both numbers are non-negative.
-
When running, the user is presented with:
- Calculation of (A^B)
- Calculation of (A!) and (B!)
- Calculation of the number of combinations (A) per (B)
- Exit
- Libraries:
stdio.hfor input/output,math.hfor mathematical functions. - Validation: Ensures errors are caught (e.g., negative factorials or invalid combinations) and displays
"Error"messages. - Operation Counter: Tracks cumulative successful executions using
sum = m_P + m_F + m_C + m_E, printed when the user exits.
This repository contains introductory laboratory material for the
Computer Programming course at the University of West Attica (UNIWA).
-
C Compiler
- Recommended:
- GCC (Linux / macOS / Windows via MinGW or WSL)
- Recommended:
-
Text Editor or IDE
- Visual Studio Code
(Recommended) - Code::Blocks
- Dev-C++
- CLion
- Any plain text editor
- Visual Studio Code
- Windows
- Linux
(Recommended) - macOS
Clone the repository to your local machine:
git clone https://github.com/Computer-Programming-aka-Uniwa/Functions.git- Open the repository URL in your browser
- Click Code → Download ZIP
- Extract the ZIP file to a local directory
cd Functions/srcgcc Hanoi.c -o Hanoi
gcc SinCosTaylor.c -o SinCosTaylor -lm
gcc Menu.c -o Menu -lm
-lmis required to link the math library
Linux / macOS
./Hanoi
./Menu
./SinCosTaylorWindows
Hanoi.exe
Menu.exe
SinCosTaylor.exe- Navigate to the
docs/directory - Open the report corresponding to your preferred language:
- English:
Subprograms.pdf - Greek:
Υποπρογράμματα.pdf
- English:
