1b - Introduction To Programming in C
1b - Introduction To Programming in C
IN C
10/23/2024 1
OUTLINE
Definitions of Terms
Programming Paradigms
Compiler Terminology
Errors
C Language
Programming Character Set
10/23/2024 2
PROGRAMS
10/23/2024 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
10/23/2024 4
WHY THE COMPUTER?
10/23/2024 5
SO HOW DO WE PROGRAM?
10/23/2024 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
10/23/2024 7
SO LET’S BEGIN!
10/23/2024 8
WHAT IS AN ALGORITHM?
An algorithm is a
Series of STEPS which when followed achieve a TASK
Transf
ingre
ormat result
dient
ion s
s
steps
Tran
sfor
inpu mati outp
t on ut
step
s
10/23/2024 9
PROGRAMMING
10/23/2024 10
ACHIEVING ACCURATE RESULTS
10/23/2024 11
DISCUSSION 1
? Which
Ingredients
? In what form
? What Process
? What Output
? In what form
10/23/2024 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)
10/23/2024 13
DISCUSSION 3 – SO WHAT ARE REQUIRED
CHARACTERISTICS OF PROGRAMS
10/23/2024 14
SIMPLE PROGRAMMING MODEL
Fry two whole eggs.
input
10/23/2024 15
REAL PROGRAMMING MODEL
Input
Computer
machine
has data
Program
steps
ming =
writing
code to
manipula
te data
output
10/23/2024 16
DISCUSSION 4 (3 MINUTES)
10/23/2024 17
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
3. Object-oriented:
which objects , who? e.g. Smalltalk, C++, Java
10/23/2024 18
HOW DOES PROGRAMMING WORK?
Program
(instructions written
for someone to use
someone=user)
Compiler
(translates and
interprets
10/23/2024 19
instructions)
MORE ABOUT THE COMPILER
Source 1. Compiler:
program file Check syntax
(.c) errors
10/23/2024 21
SKILLS REQUIRED FROM YOU IN
PROGRAMMING
Attention to detail
Specific
Unambiguous
Good memory
Of syntax, defined names, names of prewritten functions
10/23/2024 22
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.
10/23/2024 23
C LANGUAGE SPECIFICS
10/23/2024 24
ASCII CHARACTER SET EXAMPLES
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
10/23/2024 25
RUNNING C PROGRAMS
10/23/2024 26
SUMMARY
Definition of programming:
steps in defined language to accomplish a particular task
Important properties of C
versatile, learnable.
Uses ASCII character set
Case-sensitive
10/23/2024 27