PROGRAMMING
CONCEPTS
CS 8104
COURSE CONTENT
Programming language overview
Introduction to C Programming
General C program
Data Types and Variables
Operators and Expressions
COURSE CONTENT
Cont..
Control Flow Statements
Functions
PROGRAMMING LANGUAGE
OVERVIEW
What is programming language?
It is a formal language that is used to
communicate instructions to a computer.
Programming languages can be divided into
three groups:
PROGRAMMING LANGUAGE
OVERVIEW
Cont..
Machine language - This is the language that
machines can understand directly, as it uses
only zeros and ones (binary).
Low-level language - These languages are
closer to machine language and use
mnemonics to represent machine instructions.
E.g. Assembly language
PROGRAMMING LANGUAGE
OVERVIEW
Cont...
High level language - These languages are
closer to the way people communicate. They
are portable and make the process of writing,
reading, and modifying programs much easier.
E.g. C++, Pascal, Python, Java, C#, Visual
Basic, JavaScript, Ruby, Perl, PHP, GO, Rust,
Swift, Kotlin, SQL etc.
PROGRAMMING LANGUAGE
OVERVIEW
Why should a student taking civil engineering learn
programming?
Enhanced Problem-Solving Skills
oProgramming fosters critical thinking and
problem-solving abilities. By learning to code,
students can break down complex engineering
problems into manageable parts, allowing them to
PROGRAMMING LANGUAGE
OVERVIEW
Automation of Repetitive Tasks:
oMany tasks such as calculations, data analysis,
and report generation, can be repetitive.
Programming allows students to automate these
tasks, saving time and reducing the likelihood of
human error. This efficiency is crucial in
PROGRAMMING LANGUAGE
OVERVIEW
Data Analysis and Visualization
oCivil engineers often work with vast amounts
of data, including soil test results, traffic
patterns, and environmental impact
assessments. Programming will equip you
with the skills to analyze and visualize this
data effectively, leading to better decision-
PROGRAMMING LANGUAGE
OVERVIEW
Integration with Advanced Technologies
oThe construction industry is increasingly
adopting advanced technologies such as
Building Information Modeling (BIM),
Geographic Information Systems (GIS), and
Finite Element Analysis (FEA).
PROGRAMMING LANGUAGE
OVERVIEW
Cont..
oProficiency in programming allows you to
leverage these tools, customize applications,
and enhance their functionality through
scripting or developing plugins.
PROGRAMMING LANGUAGE
OVERVIEW
Computational Design and Simulation:
oProgramming is essential for conducting
simulations that predict how structures will
behave under various conditions. For
instance, finite element methods used in
structural analysis require coding knowledge
to set up simulations and interpret results
PROGRAMMING LANGUAGE OVERVIEW
Career Competitiveness:
oAs the demand for tech-savvy professionals
grows in the civil engineering sector,
programming skills become a significant
asset. Employers increasingly seek
candidates who can integrate traditional
engineering principles with modern
PROGRAMMING LANGUAGE OVERVIEW
Supporting Sustainable Practices:
oProgramming can aid in modeling
environmental impacts and optimizing
designs for sustainability. By simulating
different scenarios, civil engineers can make
informed decisions that minimize ecological
footprints.
PROGRAMMING LANGUAGE OVERVIEW
Collaboration Across Disciplines:
oCivil engineering projects often involve
collaboration with professionals from various
fields such as architecture, environmental
science, and urban planning.
PROGRAMMING LANGUAGE OVERVIEW
Cont..
oProgramming skills enable civil engineers to
communicate more effectively with these
professionals by understanding and
integrating different technological tools and
methodologies.
INTRODUCTION TO C
PROGRAMMING
This section covers the following items;
The history of the language
Features of the language
Applications of the language
INTRODUCTION TO C
PROGRAMMING
What is C programming language?
Is a general-purpose, procedural, and mid-
level programming language that provides
low-level access to system memory
HISTORY OF C LANGUAGE:
The C Language was developed by Dennis
Ritchie for creating system applications that
directly interact with the hardware devices such
as drivers, kernels, etc.
FEATURES OF C LANGUAGE:
Simple and Efficient: C is a simple language
that is easy to learn and use. It is also efficient
FEATURES OF C LANGUAGE
Portable: C programs are machine-
independent, which means that they can be
run on different machines with little or no
machine-specific changes.
Structured Programming Language: It allows
programmers to break a program into parts
using functions.
FEATURES OF C LANGUAGE
Mid-Level Programming Language: It provides low-
level access to the computer hardware while being
easy to use, portable, and supporting all other
features of a high-level language.
Rich Standard Library: C provides a rich set of
library functions and data types that make
development fast and efficient.
APPLICATIONS OF THE
LANGUAGE
Operating Systems
Language Compilers
Assemblers
Text Editors
Print Spoolers
APPLICATIONS OF THE
LANGUAGE
Network Drivers
Modern Programs
Databases
Language Interpreters
Utilities
GENERAL C PROGRAM
A C program generally consists of the following
components;
Preprocessor Commands
Functions
Variables
Statements & Expressions
Comments
A C PROGRAM GENERALLY
CONSISTS OF THE
FOLLOWING COMPONENTS
#include <stdio.h>
int main() {
/* my first program in C */
printf("Hello, World! \n");
return 0;
}
EXPLANATION OF THE COMPONENTS
#include <stdio.h> is a preprocessor command,
tells a C compiler to include stdio.h file before
going to actual compilation.
int main() is the main function where the program
execution begins.
/*...*/ or // Statement ignored by the compiler and
it put to add additional comments in the program.
EXPLANATION OF THE
COMPONENTS
Cont..
printf(...) is another function available in C
which causes the message to be displayed.
return 0; terminates the main() function and
returns the value 0.
SOURCE CODE AND
EXECUTABLE CODE
These are two different forms of computer
code explained as;
Source Code - is the human-readable version
of a program that is written by a programmer
using a high-level programming language
such as C, Python, or Java.
SOURCE CODE AND
EXECUTABLE CODE
It contains comments, variable names, and
other elements that make it easier for
humans to read and understand.
Source code is compiled or interpreted to
produce executable code.
SOURCE CODE AND
EXECUTABLE CODE
Executable Code - is the machine-readable
version of a program that is produced by
compiling or interpreting the source code.
It contains binary instructions that can be
executed directly by a computer's processor.
Executable code is not human-readable and
cannot be easily modified by humans.
EDITOR, ASSEMBLER,
COMPILER AND LINKER
Editor
Is a software tool used for creating and
modifying text files, including source code
files.
It provides a user-friendly interface for
editing text and may include features such as
syntax highlighting, auto-completion, and
EDITOR, ASSEMBLER,
COMPILER AND LINKER
Text editors are used by programmers to
write and modify source code for software
programs, scripts, and web pages.
Some popular text editors include Notepad+
+, Sublime Text, and Visual Studio Code.
EDITOR, ASSEMBLER,
COMPILER AND LINKER
Assembler
Is a program that translates assembly code
into machine code.
Assembly code is a low-level programming
language that is specific to a particular
machine architecture.
EDITOR, ASSEMBLER,
COMPILER AND LINKER
Linker
Is a program that resolves the unresolved
references in the object file and generates an
executable file.
It reads all the object files generated by the
compiler and assembler and combines them
into a single executable file.
SAVING AND COMPILING A C
PROGRAM
Steps to follow;
Open a text editor and write your source code.
Save the file with the any name but with an
extension of .c. E.g. hello.c
Compile your code.
SAVING AND COMPILING A C
PROGRAM
If there are no errors in your code, the
command prompt will take you to the next
line and would generate a.out executable
file.Now select execute.
You will see the output E.g. "Hello World"
printed on the screen.
DATA TYPES AND VARIABLES
On this section, we are going to cover the
following;
Data types
Declaring and using data type in a C program.
Variable
DATA TYPE
Specifies the type of data that a variable can
store such as integer, floating, character, etc.
These data types can be classified as the
following;
Basic - int, char, float, double.
Derived
Enumeration
BASIC DATA TYPE
Integer:
Integers are entire numbers without any
fractional or decimal parts, and (int) data type
is used to represent them.
BASIC DATA TYPE
Float:
Floating numbers can be used to represent
fractional units or numbers with decimal
places.
BASIC DATA TYPE
Char:
Typically used to hold ASCII or UTF-8 encoding
scheme characters, such as letters, numbers,
symbols, or commas.
There are 256 characters that can be
represented by a single char, which takes up
one byte of memory. Characters such as 'A',
'b', '5', or '$' are enclosed in single quotes.
BASIC DATA TYPE
Double:
Use two data types to represent two floating
integers. When additional precision is needed,
such as in scientific calculations or financial
applications, it provides greater accuracy
compared to float.
BASIC DATA TYPE
Keywords
A keyword is a reserved word.
You cannot use it as a variable name, constant
name, etc.
Examples are such as auto, break, case, char,
const, continue, default, do, double, else,
enum etc.
DECLARING AND USING
DATA TYPE IN A C
PROGRAM.
Identifier:
Is a collection of alphanumeric characters that
begins either with an alphabetical character or
an underscore, which are used to represent
various programming elements. E.g. variables,
functions, arrays, structures, unions, labels,
etc.
There are 52 alphabetical characters
(uppercase and lowercase), underscore
character, and ten numerical digits (0-9). In
DECLARING AND USING
DATA TYPE IN A C
PROGRAM.
Cont..
E.g. int myVariable;
"myVariable" is an identifier for an integer
variable.
The first letter is a lowercase letter, and the
rest of the letters are also lowercase.
DECLARING AND USING
DATA TYPE IN A C
PROGRAM.
Data types are used to declare variables or
functions with different types of data.
Examples;
int myInt;
char myChar = 'a';
float myFloat = 3.14;
double myDouble = 3.14159265359;
FORMAT SPECIFIERS
Are used to tell the compiler about the type of
data to be printed or scanned in input and
output operations.
They always start with a % symbol and are
used in the formatted string in functions like
printf(), scanf etc.
The C language provides a number of format
specifiers such as %d for int, %c for char, %f
for float, and so on.
AMPERSAND IN C
The "&" symbol is used as the address of
operator. It returns the memory location of a
variable.
Different use of Ampersand
To get the memory address of a variable.
Used in front of a variable to get its address.
The ampersand is also used to pass the
address of a variable to a function.
VARIABLE
Is a user-defined name assigned to a memory
location that holds a value that can be
modified and reused many times during the
program execution.
They store data of different types such as
integer, character, float and double.
Variable helps the compiler know what data
type to expect and which operations can be
performed.
The syntax for declaring a variable in C is as
follows:
<data type> <variable name>;
CONSTANT
Is a value that cannot be modified once it is
declared in the program.
Constants are similar to variables, but their
values remain fixed throughout the execution
of the program.
RESOURCES
Reading resource:
https://www.w3schools.com/c/index.php
Online text editor for practice:
https://www.programiz.com/c-programming/onli
ne-compiler/