Skip to content

Introductory C programming examples demonstrating iterative structures (for, while, do-while), loop control (break, continue), and practical applications like Taylor series, integer operations, and pattern printing (Computer Programming, UNIWA).

Notifications You must be signed in to change notification settings

Computer-Programming-aka-Uniwa/Loops

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

UNIWA

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


Computer Programming

Loops

Vasileios Evangelos Athanasiou
Student ID: 19390005

GitHub · LinkedIn

Supervisor: Georgios Meletiou, Laboratory Teaching Staff

UNIWA Profile

Athens, December 2021


Project Overview

This project explores the fundamental concepts of iterative structures (loops) in the C programming language. It provides a comprehensive theoretical background followed by practical implementations through various source code examples.


Table of Contents

Section Folder / File Description
1 assign/ Assignment material
1.1 assign/project4.png Assignment description / problem statement (English)
1.2 assign/εργασία4.png Assignment description / problem statement (Greek)
2 docs/ Theoretical documentation
2.1 docs/Loops.pdf Loops and iteration in C (English)
2.2 docs/Βρόχοι.pdf Loops and iteration in C (Greek)
3 src/ Source code implementations
3.1 src/MathsWithIntegersInLoopA.c Integer operations using for/while loops (example A)
3.2 src/MathsWithIntegersInLoopB.c Integer operations using for/while loops (example B)
3.3 src/SinTaylor.c Computing sine using Taylor series in loops
3.4 src/Stars.c Loop exercises: printing patterns (stars)
4 README.md Repository overview and instructions

Theoretical Background

Iterative Structures

Iterative structures are instructions that execute a body of code repeatedly based on a specific condition.

  • The loop continues while the condition is true (non-zero)
  • Terminates when the condition becomes false (zero)

Supported Loops in C:

  • while: Executes a body of instructions as long as the condition evaluates to true.
  • do-while: Executes the loop body at least once, then checks the condition.
  • for: Commonly used for a predetermined number of iterations, accepts initialization, condition, and modification.

Control Commands

  • break: Immediately exits the loop and continues execution after the loop.
  • continue: Skips the current iteration and moves to the next loop cycle.

Source Code Implementations

1. MathsWithIntegersInLoopA.c

Performs mathematical operations on a user-defined number of integers.

Functionality:

  • Calculates the square of odd numbers
  • Counts the number of even numbers
  • Computes the average of positive numbers
  • Computes the product of negative numbers

Key Logic:
Uses a while loop that iterates until the counter i reaches the user-specified limit N.


2. Stars.c

Visualizes geometric shapes using asterisks (*) based on user input for the number of lines.

Functionality:

  • Plots four distinct asterisk-based figures
    • Figure 1: Right-angled triangle
    • Figure 4: Square perimeter with diagonal markings

Key Logic:
Uses nested for loops to handle row and column positions for characters.


3. SinTaylor.c

Calculates the sine of an angle using the Taylor series and compares it with the standard library sin() function.

Functionality:

  • Converts user-inputted degrees to radians
  • Iteratively computes Taylor series terms until the difference between successive terms < 10⁻⁶

Key Logic:

  • Uses a do-while loop to sum series terms
  • Alternates addition and subtraction using a sign toggle variable

Installation & Setup Guide

This repository contains introductory laboratory material for the
Computer Programming course at the University of West Attica (UNIWA).


Prerequisites

Required Software

  • C Compiler

    • Recommended:
      • GCC (Linux / macOS / Windows via MinGW or WSL)
  • Text Editor or IDE

    • Visual Studio Code (Recommended)
    • Code::Blocks
    • Dev-C++
    • CLion
    • Any plain text editor

Supported Operating Systems

  • Windows
  • Linux (Recommended)
  • macOS

Installation

1. Clone the Repository

Clone the repository to your local machine:

git clone https://github.com/Computer-Programming-aka-Uniwa/Control.git

Alternative (Without Git)

  • Open the repository URL in your browser
  • Click Code → Download ZIP
  • Extract the ZIP file to a local directory

Compiling & Running the Programs

2. Navigate to Source Directory

cd Loops/src

3. Compile the Programs

gcc MathsWithIntegersInLoopA.c -o MathsWithIntegersInLoopA
gcc MathsWithIntegersInLoopB.c -o MathsWithIntegersInLoopB
gcc Stars.c -o Stars
gcc SinTaylor.c -o SinTaylor -lm

-lm is required to link the math library

4. Run the Programs

Linux / macOS

./MathsWithIntegersInLoopA
./MathsWithIntegersInLoopB
./Stars
./SinTaylor

Windows

MathsWithIntegersInLoopA.exe
MathsWithIntegersInLoopB.exe
Stars.exe
SinTaylor.exe

Open the Documentation

  1. Navigate to the docs/ directory
  2. Open the report corresponding to your preferred language:
    • English: Loops.pdf
    • Greek: Βρόχοι.pdf

About

Introductory C programming examples demonstrating iterative structures (for, while, do-while), loop control (break, continue), and practical applications like Taylor series, integer operations, and pattern printing (Computer Programming, UNIWA).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages