0% found this document useful (0 votes)
3 views

1b - Introduction to Programming in C

The document provides an introduction to programming in C, covering key concepts such as definitions of programming, programming paradigms, compiler terminology, and common errors. It emphasizes the importance of algorithms, precise instructions, and the characteristics of effective programs, while also detailing the specifics of the C language and its syntax. Additionally, it discusses the role of compilers and the skills required for programming, highlighting C as a versatile and learnable language.

Uploaded by

Sean Martin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

1b - Introduction to Programming in C

The document provides an introduction to programming in C, covering key concepts such as definitions of programming, programming paradigms, compiler terminology, and common errors. It emphasizes the importance of algorithms, precise instructions, and the characteristics of effective programs, while also detailing the specifics of the C language and its syntax. Additionally, it discusses the role of compilers and the skills required for programming, highlighting C as a versatile and learnable language.

Uploaded by

Sean Martin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 28

INTRODUCTION TO PROGRAMMING

IN C

06/01/2025 1
OUTLINE

 Definitions of Terms
 Programming Paradigms
 Compiler Terminology
 Errors
 C Language
 Programming Character Set

06/01/2025 2
PROGRAMS

 What is the general meaning?


 Noun
 A program of actions or events is a series of
actions or events that are planned to be done.
 Verb
 When you program a machine or system, you
set its controls so that it will work in a particular
way.
06/01/2025 3
FOCUS
 Programming a machine
 Giving it instructions that it understands word for word
 Speak to it in a particular language
 How does the machine know which language?
 The machine must have some kind of brain in it
(residing in processor, hard drive etc.)
 What kind of machines?
 Phones, computers, scanners, conveyor belts, electric
jugs, factory machines, microwaves, smart-watches
 Which machine for this course?
 Computer
06/01/2025 4
WHY THE COMPUTER?

 Can be connected to other machines to


make them work
 Program can be translated so that other
machines understand it
 Computer serves as platform to test the
program and simulate it before mounting it
on big machines
 Most machines now computer controlled
06/01/2025 5
SO HOW DO WE PROGRAM?

 First determine steps required to achieve a


particular functionality or task
 Algorithm
 Then translate the steps into precise steps
 Program

06/01/2025 6
ARE ALL PROGRAMS WRITTEN THE SAME
WAY?

 NO
 Different languages (means different ways of
translating hence different translators)
 Different syntax (i.e. Grammar and
punctuation)
 Different functionalities achievable
 Some more complex than others

06/01/2025 7
SO LET’S BEGIN!

06/01/2025 8
WHAT IS AN ALGORITHM?
 An algorithm is a
 Series of STEPS which when followed achieve a
TASK
 It is much like a recipe
Transformati
ingredients on steps results

Transformati
input output
on steps

06/01/2025 9
PROGRAMMING
 Telling the computer what to do
 Giving instructions in a language understood by
the computer
 Instructions follow the algorithm
 Instructions are a formal writing of the algorithm
 Program = Complete set of formal
instructions
 For accurate, expected results, Instructions must be
 Precise
 Unambiguous 06/01/2025 10
ACHIEVING ACCURATE RESULTS

Logical sequential algorithm


Clearly defined data to be used
Clearly defined form of the input data
Clearly defined form of the expected
results (i.e. Output as we call it)
06/01/2025 11
DISCUSSION 1

 Give an algorithm to prepare two whole fried eggs, unscrambled (2


minutes)

? Which
Ingredients
? In what form
? What Process
? What Output
? In what form

06/01/2025 12
DISCUSSION 2 – COMMENT ON THE RICE
ALGORITHMS
 Points to note:
 Algorithms are NOT specific
 in measures of ingredients
 on where or how the ingredients are stored,
 on utensils to be used,
 on size of utensils to be used
 on time , time varies per group and per exposure
 Results
 Inaccurate (too much rice or too little rice)
 Inconsistent (raw rice or overcooked rice)
06/01/2025 13
DISCUSSION 3 – SO WHAT ARE REQUIRED
CHARACTERISTICS OF PROGRAMS

 Requirements of algorithms and


programs
 Accurate measures of inputs
 Accurate measures of time
 Accurate results
 Consistent results

06/01/2025 14
SIMPLE PROGRAMMING MODEL
 Cook Rice.

• What is
required
before we steps
start • What are the
actually • What steps
do we carry results of the
cooking the
out in the steps we
rice?
cooking of carried out?
the rice?
outp
input ut
06/01/2025 15
REAL PROGRAMMING MODEL

Inpu
t
Computer
machine has
data
step Programming =
s writing code
to manipulate
data
outp
ut
06/01/2025 16
DISCUSSION 4 (3 MINUTES)
 Give an algorithm to do two things:

1. add two numbers, display the result, then


2. multiply the numbers and output the multiplication result.
(2 minutes)

 Given our previous discussion:

1. Describe the input, and output.


2. List the processing steps that transform the input into
desired output.
 Issues:
 all using different languages to write  no consistency
06/01/2025 17

 varied interpretations
DIFFERENT APPROACHES TO PROGRAMMING
 Programming Paradigm:
 way of conceptualising what it means to perform
computation and how tasks to be carried out on a
computer should be structured and organised
1. Imperative:
 how-to, algorithm explicit, goal implicit, use of functions
e.g. procedural programming, Fotran, C, C++,
functional programming (such as Haskell)
2. Declarative:
 what-is, goal explicit, algorithm implicit, use of logical
expressions e.g. Prolog
06/01/2025 18
3. Object-oriented:
 which objects , who? e.g. Smalltalk, C++, Java
PROCEDURAL PROGRAMMING
 Procedural programming is a programming
paradigm built around the idea that
programs are sequences of instructions to
be executed. They focus heavily on splitting up
programs into named sets of instructions called
procedures, analogous to functions. A procedure
can store local data that is not accessible from
outside the procedure's scope and can also access
and modify global data variables.

 Some of the earliest procedural programming


06/01/2025 19

languages were Fortran and ALGOL.


HOW DOES PROGRAMMING WORK?
Program
(instructions Compiler
written for (translates and
someone to use interprets
someone=user instructions)
)

Creating
that now Executable Code
RUNs on (invoked by user
Computer to see if it
works)
06/01/2025 20
MORE ABOUT THE COMPILER

Produce object
file not yet
Source 1. Compiler:
linked to other
program file Check syntax
invoked
(.c) errors
libraries
(.obj, .o)

Run 2. Linker:
Build final
executable file combine all
executable file
and detect object files
(.exe)
runtime errors with libraries

06/01/2025 21
ERRORS ENCOUNTERED WHEN
PROGRAMMING

Syntax (i.e. compiling) errors Runtime errors


 Un-matching braces/ brackets  Wrong results
 Wrong language constructs  Unintended output
 Registers used not defined  Division by zero (usually
 Registers not initialised caused by not controlling
input or wrong calculations)
 Invalid way of defining data
(according to language rules)

06/01/2025 22
SKILLS REQUIRED FROM YOU IN
PROGRAMMING
 Attention to detail
 Specific
 Unambiguous
 Knowing the computer is stupid
 Until you give it instructions.
 It will do exactly as you tell it to.
 Good memory
 Of syntax, defined names, names of prewritten functions
 Ability to think on several levels
 Compartmentalise into little box processes which perform23
06/01/2025

useful tasks
NOW LET’S TALK ABOUT C LANGUAGE
 Compact language
 Powerful (especially for efficient machine-
dependent programming)
 Not as heavy as industrial-type languages
like Php, Java
 Syntax heavily influenced industrial-type
languages
 One of the best teaching languages.
06/01/2025 24
C LANGUAGE SPECIFICS

 Case sensitivity (all these are different!)


Myname2 myName2 Myname2
my_name2 MYname2 MYNAME2

 Uses a specific alphabet


 ASCII character set
 Each letter has different numeric equivalent
 Each letter represented as a binary number
06/01/2025 25
ASCII CHARACTER SET EXAMPLES (see
course outline for full set)
CHAR CODE CHAR CODE CHAR CODE
, 44 a 97 ± 241
- 45 ‗ 242
b 98
. 46 ¾ 243
c 99
/ 47 ¶ 244
d 100
0 48 § 245
1 49 e 101
÷ 246
2 50 f 102
¸ 247
3 51 g 103 ° 248
4 52 A 65 ¨ 249
5 53 B 66 · 250
6 54 C 67
7 55
06/01/2025 26
RUNNING C PROGRAMS
 Integrated Development Environment (IDE)
 With built-in compiler, linker, executor
 Better if it supports later standards like C99(ISO/IEC
9899:1999) and C11(ISO/IEC 9899:2011).
 https://www.thefreecountry.com/compilers/cpp.shtml contains
a list of varied IDEs that support C programming.
 E.g. Bloodshed Dev C++, CodeBlocks, Orange C, Microsoft
Visual Studio Community (Microsoft C)

 Without built-in compiler and linker


 Requires installation of the GNU Compiler Collection gcc 4.9 to
gcc 6.3 (or later) from https://gcc.gnu.org
06/01/2025 27
SUMMARY
 Definition of programming:
 steps in defined language to accomplish a
particular task
 Important requirements of algorithms and
programs
 Precise, singular meaning, clear.
 Important properties of C
 versatile, learnable.
 Uses ASCII character set 06/01/2025 28

 Case-sensitive

You might also like