Sunteți pe pagina 1din 9

CM 101 lundamenLals of

CompuLer and programmlng ln C


rogrammlng Languages rograms
and rogrammlng
ConcepLs rogrammlng Languages
rograms and rogrammlng
rograms
A seL of
statements
wrlLLen ln a
rogramm|ng
Language and
arranged ln a
speclfled
structure
LxecuLable
nonexecuLable
Machlne
Assembly
Plgh level
Maln programs
Subprograms
101100 10110011 10111010
Auu A 8
A + 8
CperaLlon
code
Cperand
LxecuLable
sLaLemenLs
nonexecuLable
sLaLemenL
ueclaraLlons (deflnlLlons)
uaLa Lype declaraLlons
4 lnLeger daLa Lype
4 lloaLlng polnL daLa Lype
4 CharacLer daLa Lype
Iarlable declaraLlons
ConsLanL declaraLlons
rogram Lype declaraLlons
4 Maln program
4 Subprogram
erform
ArlLhmeLlc operaLlons
Loglcal operaLlons
1ransfer execuLlon conLrol operaLlons
Cause lLeraLlon
uaLa movemenL operaLlons
4 npuL devlces Lo memory
4 Memory Lo ouLpuL devlces
4 Memory Lo memory
4 Memory Lo reglsLer
4 8eglsLer Lo memory
tructures
The structure of a main program in C language
reprocessor declaraLlons
1ype declaraLlons
Iarlable declaraLlons (global)
vold maln ()

local declaraLlons
LxecuLable sLaLemenLs

luncLlon (subprogram)
declaraLlons
#n sLdloh
vold maln ()

r|ntf ( n am ln Lhe maln program")

5tJlob ls o collectloo of
sobptoqtoms fot lopot
ooJ ootpot opetotloos
llke ptlotf ()
No Jeclototloo (empty)
Molo ls oo oJJtess lo
tbe memoty lt moy
cootolo o Joto I
loJlcotes tbe type of
tbe Joto wlll be
JetetmloeJ wbeo lt wlll
cootolo o Joto voloe
No Jeclototloo (empty)
#n sLdloh vold maln ()
vold maln ()

r|ntf ( n am ln Lhe maln program")

Code SegmenL
uaLa SegmenL
a m l n L h e m m a l n p r o g r a m
Com||er
Checks Lhe
synLax
CeneraLes
codes
Com||er
Checks Lhe
synLax
CeneraLes
codes
Loader]
L|nker]
8|nder
Loads
Loader]
L|nker]
8|nder
Loads
Code |n code
segment
main
Stdio.h
Printf
Data
address
C C
AlgorlLhm Lxample
Suppose you are glven a
seL of mark sheeLs
where each mark sheeL
bears A 8 C or l leLLer
grade
WrlLe an algorlLhm Lo
read mark sheeL and
prlnL Lhe grade LhaL lL
conLalns
1 SLarL
2 1ake a mark sheeL and
read Lhe grade
3 rlnL Lhe grade
4 SLop
#lnclude sLdloh
vold maln()

char c
prlnLf (n enLer Lhe leLLer grade )
cgeLchar()
prlnLf (n Crade )
puLchar(c)
geLs()

#lnclude sLdloh
vold maln()

char c
prlnLf (n enLer Lhe leLLer grade )
cgeLchar()
prlnLf (n Crade )
puLchar(c)
geLs()

AlgorlLhm Lxample 2
Suppose you are glven a
seL of mark sheeLs
where each mark sheeL
bears A 8 C or l grade
WrlLe an algorlLhm Lo read
a mark sheeL and prlnL
lf Lhe grade ls A only
1 SLarL
2 1ake a mark sheeL and
read Lhe grade
f grade ls A Lhen rlnL Lhe
grade
4 SLop
#lnclude sLdloh
vold maln() // readlng and wrlLlng characLers
char c
prlnLf (n enLer Lhe leLLer grade)
cgeLchar()
lf( c A)

prlnLf(n 1he grade ls )


puLchar(c)

#lnclude sLdloh
vold maln() // readlng and wrlLlng characLers
char c
prlnLf (n enLer Lhe leLLer grade)
cgeLchar()
lf( c A)

prlnLf(n 1he grade ls )


puLchar(c)

AlgorlLhm Lxample 3
Suppose you are
glven a seL of mark
sheeLs where each
mark sheeL bears A
8 C or l grade
WrlLe an algorlLhm Lo
read a mark sheeL
and prlnL Lhe grade lf
lL ls A or 8 only
1 SLarL
2 1ake a mark sheeL and read Lhe grade
f grade ls A or 8 Lhen rlnL Lhe grade
4 SLop
#lnclude sLdloh
vold maln() // readlng and wrlLlng characLers
char c
prlnLf (n enLer Lhe leLLer grade)
cgeLchar()
f (( c A) | ( c 8))

r|ntf(n 1he grade |s )


utchar(c)

#lnclude sLdloh
vold maln() // readlng and wrlLlng characLers
char c
prlnLf (n enLer Lhe leLLer grade)
cgeLchar()
f (( c A) | ( c 8))

r|ntf(n 1he grade |s )


utchar(c)

Summary
rogram
Maln program
Subprogram
tatements
Lxecutab|e
Non executab|e
rogramm|ng Language
Mach|ne Language
Assemb|y Language
n|gh |eve| Language
tructure
Ma|n rogram
ubrograms
(funct|ons)
8|ocks
Com||ers
Loaders
L|nkers
nterreter s

S-ar putea să vă placă și