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, November 2021
The primary focus of this laboratory work is the theoretical understanding and practical application of control structures in C, specifically:
ifif-elseswitch
These structures are essential for directing program flow based on logical conditions and user input.
| Section | Folder / File | Description |
|---|---|---|
| 1 | assign/ |
Assignment material |
| 1.1 | assign/project3.png |
Assignment description / problem statement (English) |
| 1.2 | assign/εργασία3.png |
Assignment description / problem statement (Greek) |
| 2 | docs/ |
Theoretical documentation |
| 2.1 | docs/Control-Structures.pdf |
Control structures in C (English) |
| 2.2 | docs/Δομές-Ελέγχου.pdf |
Control structures in C (Greek) |
| 3 | src/ |
Source code implementations |
| 3.1 | src/if.c |
Basic conditional statement (if) |
| 3.2 | src/if1.c |
Extended conditional logic |
| 3.3 | src/switch.c |
Multi-branch selection (switch) |
| 3.4 | src/MaxInteger.c |
Maximum value selection using conditionals |
| 3.5 | src/2ndGradeEquation.c |
Solving a second-degree equation using control logic |
| 4 | README.md |
Repository overview and instructions |
The documentation explores the logic and syntax of conditional execution in C.
- Detailed explanation of how expressions (arithmetic, relational, or logical) are evaluated as:
- True (non-zero)
- False (zero)
- Demonstrates how evaluation results determine the execution path of a program.
- Examples of placing
ifstatements inside otherif-elsestructures. - Used to handle more complex decision-making scenarios, such as:
- Determining whether a number is negative, positive, or zero.
- Analysis of integer-based decision-making using:
casedefault
- Emphasizes the critical role of the
breakstatement in preventing unwanted fall-through behavior.
The project includes fully documented source code for the following programs:
-
if.c&if1.c- Programs designed to find the maximum of three integers.
- Implemented using:
- Nested
if-elseblocks - The ternary operator (
?:)
- Nested
-
switch.c- Demonstrates how the
switchstatement operates on integer variables. - Shows how execution flows through cases unless explicitly stopped using
break.
- Demonstrates how the
-
2ndGradeEquation.c- A comprehensive program that solves quadratic equations of the form:
The program 2ndGradeEquation.c performs the following technical functions:
- Reads three
doublecoefficients (a,b,c) from standard input.
- Calculates the discriminant:
- Determines whether the equation is:
- Quadratic (
a ≠ 0) - Linear / Degenerate (
a = 0)
- Quadratic (
-
D > 0
- Calculates two distinct real roots.
-
D = 0
- Calculates one real (double) root.
-
D < 0
- Identifies the equation as impossible in the set of real numbers.
- Formats and prints:
- Input coefficients
- Calculated roots
- Uses high numerical precision for clarity and correctness.
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/Control.git- Open the repository URL in your browser
- Click Code → Download ZIP
- Extract the ZIP file to a local directory
cd Control/srcgcc if.c -o if
gcc if1.c -o if1
gcc switch.c -o switch
gcc MaxInteger.c -o MaxInteger
gcc 2ndGradeEquation.c -o 2ndGradeEquation -lm
-lmis required to link the math library
Linux / macOS
./if
./if1
./switch
./MaxInteger
./2ndGradeEquationWindows
if.exe
if1.exe
switch.exe
MaxInteger.exe
2ndGradeEquation.exe- Navigate to the
docs/directory - Open the report corresponding to your preferred language:
- English:
Control-Structures.pdf - Greek:
Δομές-Ελέγχου.pdf
- English:
