Skip to content

Introductory C programming examples demonstrating if, if-else, switch, and quadratic equation solving, with practical source code and theory (Computer Programming, UNIWA).

Notifications You must be signed in to change notification settings

Computer-Programming-aka-Uniwa/Control

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UNIWA

UNIVERSITY OF WEST ATTICA
SCHOOL OF ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING AND INFORMATICS

University of West Attica · Department of Computer Engineering and Informatics


Computer Programming

Control Structures

Vasileios Evangelos Athanasiou
Student ID: 19390005

GitHub · LinkedIn


Supervision

Supervisor: Nikolaos Vassilas, Professor

UNIWA Profile

Co-supervisor: Georgios Meletiou, Laboratory Teaching Staff

UNIWA Profile


Athens, November 2021



README

Control Structures

The primary focus of this laboratory work is the theoretical understanding and practical application of control structures in C, specifically:

  • if
  • if-else
  • switch

These structures are essential for directing program flow based on logical conditions and user input.


Table of Contents

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 Project documentation
5 INSTALL.md Usage instructions

1. Theory Fundamentals

The documentation explores the logic and syntax of conditional execution in C.

1.1 if and if-else Statements

  • 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.

1.2 Nested Conditions

  • Examples of placing if statements inside other if-else structures.
  • Used to handle more complex decision-making scenarios, such as:
    • Determining whether a number is negative, positive, or zero.

1.3 switch Statement

  • Analysis of integer-based decision-making using:
    • case
    • default
  • Emphasizes the critical role of the break statement in preventing unwanted fall-through behavior.

2. Source Code & Documentation

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-else blocks
      • The ternary operator (?:)
  • switch.c

    • Demonstrates how the switch statement operates on integer variables.
    • Shows how execution flows through cases unless explicitly stopped using break.
  • 2ndGradeEquation.c

    • A comprehensive program that solves quadratic equations of the form:

$$ ax^2 + bx + c = 0 $$


3. Detailed Feature: Quadratic Equation Solver

The program 2ndGradeEquation.c performs the following technical functions:

3.1 Input Handling

  • Reads three double coefficients (a, b, c) from standard input.

3.2 Mathematical Analysis

  • Calculates the discriminant:

$$ D = b^2 - 4ac $$

  • Determines whether the equation is:
    • Quadratic (a ≠ 0)
    • Linear / Degenerate (a = 0)

3.3 Root Calculation

  • 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.

3.4 Output

  • Formats and prints:
    • Input coefficients
    • Calculated roots
  • Uses high numerical precision for clarity and correctness.

About

Introductory C programming examples demonstrating if, if-else, switch, and quadratic equation solving, with practical source code and theory (Computer Programming, UNIWA).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages