SlideShare a Scribd company logo
Introduction ttoo PPrrooggrraammmmiinngg 
LLeeccttuurree 1122
Today’s LLeeccttuurree IInncclluuddeess 
 SSttrriinnggss (( cchhaarraacctteerr aarrrraayyss )) 
 AAllggoorriitthhmmss uussiinngg aarrrraayyss 
 MMuullttii--ddiimmeennssiioonnaall aarrrraayyss
cchhaarr nnaammee 
[[ 110000 ]] ;;
00
IInn CC wwee hhaavvee UUsseedd 
nn NNeeww LLiinnee 
tt TTaabb CChhaarraacctteerr 
00 NNuullll CChhaarraacctteerr 
AAllll CC ssttrriinnggss aarree tteerrmmiinnaatteedd bbyy NNuullll cchhaarraacctteerr
Character AArrrraayy iinn 
MMeemmoorryy 
cchhaarr nnaammee [[ 110000 ]] ;; 
ccoouutt <<<< ““ PPlleeaassee eenntteerr yyoouurr nnaammee 
”” ;; 
cciinn >>>> nnaammee ;;
Initializing aann AArrrraayy 
IInniittiiaalliizziinngg aarrrraayy ooff iinntteeggeerrss 
iinntt cc [[ 1100 ]] == {{ 11,,22,,3,,4,,5,,6,,7,,8,,9,,1100 }} ;; 
iinntt cc [[ ]] == {{ 11,,22,,3,,4,,5,,6,,7,,8,,9,,1100 }} ;; 
FFoorr cchhaarraacctteerr aarrrraayyss 
cchhaarr nnaammee [[ 110000 ]] == {{ ‘‘aa’’,,bb’’,,’’cc’’,,’’00’’,,’’11’’ }} ;; 
cchhaarr nnaammee [[ 110000 ]] == ““aabbcc0011““ ;; 
cchhaarr nnaammee [[ ]] == ““HHeelllloo WWoorrlldd““ ;;
CChhaarraacctteerr AArrrraayyss 
TToo rreeaadd nnaammee ffrroomm kkeeyybbooaarrdd aanndd 
ddiissppllaayy iitt oonn ssccrreeeenn 
cchhaarr nnaammee [[ 110000 ]] ;; 
ccoouutt <<<< ““ PPlleeaassee eenntteerr yyoouu nnaammee”” ;; 
cciinn >>>> nnaammee ;; 
ccoouutt <<<< nnaammee ;;
CChhaarraacctteerr AArrrraayyss 
DDiissppllaayyiinngg nnaammee oonn ssccrreeeenn uussiinngg lloooopp 
ffoorr (( ii == 00 ;; ii << 110000 ;; ii ++++ )) 
{{ 
ccoouutt <<<< nnaammee [[ ii ]] ;; 
}}
Comparing TTwwoo aarrrraayyss 
AArrrraayy ssiizzee sshhoouulldd bbee eeqquuaall 
Condition : 
iinntt eeqquuaall == 00 ;; 
iinntt nnuumm11 [[ 110000 ]] ,, nnuumm22 [[ 110000 ]] ;; 
ffoorr (( ii == 00 ;; ii << 110000 ;; ii ++++ )) 
{{ 
iiff (( nnuumm11 [[ ii ]] !!== nnuumm22 [[ ii ]] )) 
{{ 
eeqquuaall == 11 ;; 
bbrreeaakk ;; 
}} 
}} 
iiff (( eeqquuaall ====11 )) 
ccoouutt <<<< ““ TThhee aarrrraayyss aarree nnoott eeqquuaall”” ;; 
eellssee 
ccoouutt <<<< ““ TThhee aarrrraayyss aarree eeqquuaall”” ;;
CCoommppaarriinngg TTwwoo 
AArrrraayyss 
AAZZMMAATT 
HHAAMMEEEEDD 
AAzzmmaatt HHaammeeeedd
EExxeerrcciissee 
 IInnppuutt yyoouurr nnaammee aanndd ddiissppllaayy iitt iinn 
rreevveerrssee oorrddeerr 
 DDeetteerrmmiinnee tthhee lleennggtthh ooff cchhaarraacctteerr 
aarrrraayy
SSoorrttiinngg 
 BBuubbbbllee SSoorrtt 
 QQuuiicckk SSoorrtt
BBrruuttee--FFoorrccee 
TTeecchhnniiqquuee 
44 
2233 
9 
6677 
[0] 
[1] 
[2] 
[16] 
[99] 
11
SSwwaappppiinngg 
6666 
6666 
4444 
3333 
33 
110000 
Memory 
Location 
[0] 
[1] 
[2] 
[16] 
[99]
SSwwaappppiinngg TTwwoo 
NNuummbbeerrss 
iinntt nnuumm [[ ]] ;; 
iinntt xx ;; 
xx == nnuumm [[ 00 ]] ;; 
nnuumm [[ 00 ]] == nnuumm [[ 1155 ]] ;; 
nnuumm [[ 1155 ]] == xx ;;
BBiinnaarryy SSeeaarrcchh 
AAllggoorriitthhmmss 
DDiivviiddee aanndd CCoonnqquueerr rruullee 
11 22 33 44 55 66 77 88 
11 22 33 44 
55 66 77 88 
11 22 33 44
Binary SSeeaarrcchh AAllggoorriitthhmm 
 IIff wwee tthhiinnkk aabboouutt iitt ,, iitt iiss 
llooggnn lloogg22 
 TToottaall aarrrraayy ssiizzee wwiillll bbee 22nn aanndd nnuummbbeerr 
ccaann bbee ffoouunndd iinn nn ttiimmeess 
 IIff 11000000 nnuummbbeerrss tthheenn 1100 ttrriieess aarree mmaaxx 
221100 == 11002244
Is divide and conquer the ffaasstteesstt wwaayy,, aallll 
tthhee ttiimmee,, ooff sseeaarrcchhiinngg ffoorr aa nnuummbbeerr iinn aa lliisstt 
?? 
11 Linear Search ? 
22 
33 
110000 
Binary Search ? 
Suppose they are Random 
Suppose they are Ordered 
Suppose they are mixed-up
FFuunnccttiioonnss aanndd 
AArrrraayyss
Sending AArrrraayyss iinnttoo 
AAnnootthheerr FFuunnccttiioonnss 
 NNaammee ooff tthhee 
aarrrraayy 
 SSiizzee ooff tthhee aarrrraayy
EExxaammppllee 11 
Declaration 
cchhaarr nnaammee [[ 110000 ]] ;; 
Function Call 
rreevveerrssee (( nnaammee ,, 110000 )) ;;
EExxaammppllee 11 
Prototype 
vvooiidd rreevveerrssee (( cchhaarr [[ ]] ,, iinntt )) ;; 
Definition 
vvooiidd rreevveerrssee (( cchhaarr cchhaarraacctteerrss [[ ]] ,, iinntt aarrrraayySSiizzee)) 
{{ 
rreevveerrssee tthhee cchhaarraacctteerr ssttrriinngg;; 
}}
EExxaammppllee 11 
mmaaiinn (( )) 
{{ 
cciinn >>>> nnaammee [[ ]] ;; 
rreevveerrssee (( cchhaarraacctteerr [[ ]] ,, aarrrraayySSiizzee )) ;; 
ccoouutt <<<< nnaammee [[ ]] ;; 
}} 
What will it 
Show ?
CCaallll bbyy RReeffeerreennccee 
&& AAddddrreessss OOppeerraattoorr 
** PPooiinntteerr OOppeerraattoorr 
IInn ccaassee ooff aarrrraayyss ,, ccaallll bbyy rreeffeerreennccee iiss ddeeffaauulltt
X iiss aa vvaarriiaabbllee wwhhiicchh iiss aa llooccaattiioonn iinn tthhee 
mmeemmoorryy 
NNaammee [[ ]] iiss aann aarrrraayy 
-- -- -- -- -- -- -- -- 
Array called Name 
Starting 
address 
Memory 
name
EExxaammppllee 22 
vvooiidd ff (( iinntt [[ ]] ,, iinntt )) ;; 
mmaaiinn (( )) 
{{ 
iinntt nnuummbbeerrss [[ 110000 ]] ;; 
ff (( nnuummbbeerrss ,, 110000)) ;; 
ffoorr (( iinntt ii == 00 ;; ii << 110000 ;; ii ++++)) 
ccoouutt <<<< nnuummbbeerrss [[ ii ]] ;; 
}}
EExxaammppllee 22 
vvooiidd ff (( iinntt xx [[ ]] ,, iinntt aarrrraayySSiizzee )) 
{{ 
iinntt ii ;; 
ffoorr (( ii == 00 ;; ii << aarrrraayySSiizzee ;; ii ++++)) 
xx [[ ii ]] == ii ;; 
}}
ff (( xx [[ 33 ]] )) ;; 
EExxeeccuutteedd wwiitthh ccaallll bbyy 
vvaalluuee,, nnoott bbyy rreeffeerreennccee
 WWhheenneevveerr aa vvaarriiaabbllee iiss ppaasssseedd ,, iitt 
iiss ppaasssseedd bbyy vvaalluuee 
 WWhheenneevveerr yyoouu ppaassss aann aarrrraayy ttoo 
ffuunnccttiioonn,, iitt iiss ccaalllleedd bbyy rreeffeerreennccee
VVeeccttoorr 
22 DDiimmeennssiioonnaall 
33 DDiimmeennssiioonnaall 
DDoott PPrroodduucctt 
VVeeccttoorr PPrroodduucctt
MMaattrriixx 
Rows 
Columns
TTwwoo DDiimmeennssiioonnaall 
AArrrraayy 
iinntt xx [[ 22 ]] [[ 33 ]] ;;
EExxaammppllee 33 
iinntt mmaaxxRRoowwss == 22;; 
iinntt mmaaxxCCoollss == 33 ;; 
iinntt mmaattrriixx [[ 22]] [[ 33 ]];; 
iinntt rrooww ,, ccooll ;; 
ffoorr (( rrooww == 00 ;; rrooww << mmaaxxRRoowwss ;; rrooww ++++ )) 
{{ 
ffoorr (( ccooll == 00 ;; ccooll << mmaaxxCCoollss ;; ccooll ++++ )) 
{{ 
ccoouutt <<<< ““PPlleeaassee eenntteerr vvaalluuee ooff ””<<<< rrooww <<<< ““ ““ <<<< ccooll;; 
cciinn >>>> mmaattrriixx [[ rrooww ]] [[ ccooll ]] ;; 
}} 
}}
55 22 99 
55 22 99 
77 00 44 
After first outer loop 
After second outer 
loop 
Input 
Input 
[0] 
[0] 
[1]
TThhrreeee DDiimmeennssiioonnaall 
AArrrraayyss 
iinntt xx [[ ]] [[ ]] [[ ]] ;;

More Related Content

PPT
CS201- Introduction to Programming- Lecture 15
PPT
CS201- Introduction to Programming- Lecture 20
PPT
CS201- Introduction to Programming- Lecture 07
PPT
CS201- Introduction to Programming- Lecture 16
PPT
CS201- Introduction to Programming- Lecture 14
PPT
CS201- Introduction to Programming- Lecture 10
PPT
Edit data base menggunakan web
PPT
CS201- Introduction to Programming- Lecture 30
CS201- Introduction to Programming- Lecture 15
CS201- Introduction to Programming- Lecture 20
CS201- Introduction to Programming- Lecture 07
CS201- Introduction to Programming- Lecture 16
CS201- Introduction to Programming- Lecture 14
CS201- Introduction to Programming- Lecture 10
Edit data base menggunakan web
CS201- Introduction to Programming- Lecture 30

What's hot (20)

PPT
CS201- Introduction to Programming- Lecture 34
PPT
CS201- Introduction to Programming- Lecture 11
PPT
CS201- Introduction to Programming- Lecture 26
PPT
CS201- Introduction to Programming- Lecture 03
PPT
CS201- Introduction to Programming- Lecture 28
PPT
CS201- Introduction to Programming- Lecture 40
PPT
CS201- Introduction to Programming- Lecture 13
PPT
CS201- Introduction to Programming- Lecture 36
PPT
CS201- Introduction to Programming- Lecture 37
PPT
CS201- Introduction to Programming- Lecture 08
PPT
Day 8 initegrations review
PPT
CS201- Introduction to Programming- Lecture 38
PPT
CS201- Introduction to Programming- Lecture 06
PPT
CS201- Introduction to Programming- Lecture 25
PPT
anatomy of the larynx
PPT
Tres clases de obras. 1º obras de la carne
PPT
CS201- Introduction to Programming- Lecture 33
PPT
CS201- Introduction to Programming- Lecture 09
PDF
निर्माण खंड 1 के एटलस. hindi हिन्दी
PPT
CS201- Introduction to Programming- Lecture 44
CS201- Introduction to Programming- Lecture 34
CS201- Introduction to Programming- Lecture 11
CS201- Introduction to Programming- Lecture 26
CS201- Introduction to Programming- Lecture 03
CS201- Introduction to Programming- Lecture 28
CS201- Introduction to Programming- Lecture 40
CS201- Introduction to Programming- Lecture 13
CS201- Introduction to Programming- Lecture 36
CS201- Introduction to Programming- Lecture 37
CS201- Introduction to Programming- Lecture 08
Day 8 initegrations review
CS201- Introduction to Programming- Lecture 38
CS201- Introduction to Programming- Lecture 06
CS201- Introduction to Programming- Lecture 25
anatomy of the larynx
Tres clases de obras. 1º obras de la carne
CS201- Introduction to Programming- Lecture 33
CS201- Introduction to Programming- Lecture 09
निर्माण खंड 1 के एटलस. hindi हिन्दी
CS201- Introduction to Programming- Lecture 44
Ad

Viewers also liked (19)

PPS
CS101- Introduction to Computing- Lecture 44
PPT
CS201- Introduction to Programming- Lecture 43
PPS
ENG101- English Comprehension- Lecture 23
PPS
ENG101- English Comprehension- Lecture 40
PPT
MGT101 - Financial Accounting- Lecture 33
PPT
CS201- Introduction to Programming- Lecture 19
PPS
ENG101- English Comprehension- Lecture 43
DOC
MTH101 - Calculus and Analytical Geometry- Lecture 41
PPT
CS201- Introduction to Programming- Lecture 35
PPS
ENG101- English Comprehension- Lecture 36
PPT
MGT101 - Financial Accounting- Lecture 27
PPT
MGT101 - Financial Accounting- Lecture 36
PPS
ENG101- English Comprehension- Lecture 28
PPT
CS201- Introduction to Programming- Lecture 39
PPT
CS201- Introduction to Programming- Lecture 32
PPS
CS101- Introduction to Computing- Lecture 32
PPS
CS101- Introduction to Computing- Lecture 29
PPS
CS101- Introduction to Computing- Lecture 39
PPT
MGT101 - Financial Accounting- Lecture 44
CS101- Introduction to Computing- Lecture 44
CS201- Introduction to Programming- Lecture 43
ENG101- English Comprehension- Lecture 23
ENG101- English Comprehension- Lecture 40
MGT101 - Financial Accounting- Lecture 33
CS201- Introduction to Programming- Lecture 19
ENG101- English Comprehension- Lecture 43
MTH101 - Calculus and Analytical Geometry- Lecture 41
CS201- Introduction to Programming- Lecture 35
ENG101- English Comprehension- Lecture 36
MGT101 - Financial Accounting- Lecture 27
MGT101 - Financial Accounting- Lecture 36
ENG101- English Comprehension- Lecture 28
CS201- Introduction to Programming- Lecture 39
CS201- Introduction to Programming- Lecture 32
CS101- Introduction to Computing- Lecture 32
CS101- Introduction to Computing- Lecture 29
CS101- Introduction to Computing- Lecture 39
MGT101 - Financial Accounting- Lecture 44
Ad

Similar to CS201- Introduction to Programming- Lecture 12 (18)

PPT
CS201- Introduction to Programming- Lecture 22
PPT
CS201- Introduction to Programming- Lecture 21
PPT
CS201- Introduction to Programming- Lecture 27
PPT
CS201- Introduction to Programming- Lecture 29
PPT
Penetration testing: A proactive approach to secure computing - Eric Vanderbu...
PPT
CS201- Introduction to Programming- Lecture 31
PPT
Syrah clones for warm climates
PPT
Syrah clones for warm climates
PPT
Fund analysis and cash flow analysis
PPT
CS201- Introduction to Programming- Lecture 04
PPT
CS201- Introduction to Programming- Lecture 05
PPT
CS201- Introduction to Programming- Lecture 42
PPT
Ian copsey integrated ta
PPT
Teaching English grammar
ODP
7 Years of Puppet Horror Stories
PPT
CS201- Introduction to Programming- Lecture 24
PPT
Employee benefits and compensation
PPT
Mba ebooks
CS201- Introduction to Programming- Lecture 22
CS201- Introduction to Programming- Lecture 21
CS201- Introduction to Programming- Lecture 27
CS201- Introduction to Programming- Lecture 29
Penetration testing: A proactive approach to secure computing - Eric Vanderbu...
CS201- Introduction to Programming- Lecture 31
Syrah clones for warm climates
Syrah clones for warm climates
Fund analysis and cash flow analysis
CS201- Introduction to Programming- Lecture 04
CS201- Introduction to Programming- Lecture 05
CS201- Introduction to Programming- Lecture 42
Ian copsey integrated ta
Teaching English grammar
7 Years of Puppet Horror Stories
CS201- Introduction to Programming- Lecture 24
Employee benefits and compensation
Mba ebooks

CS201- Introduction to Programming- Lecture 12

  • 2. Today’s LLeeccttuurree IInncclluuddeess  SSttrriinnggss (( cchhaarraacctteerr aarrrraayyss ))  AAllggoorriitthhmmss uussiinngg aarrrraayyss  MMuullttii--ddiimmeennssiioonnaall aarrrraayyss
  • 3. cchhaarr nnaammee [[ 110000 ]] ;;
  • 4. 00
  • 5. IInn CC wwee hhaavvee UUsseedd nn NNeeww LLiinnee tt TTaabb CChhaarraacctteerr 00 NNuullll CChhaarraacctteerr AAllll CC ssttrriinnggss aarree tteerrmmiinnaatteedd bbyy NNuullll cchhaarraacctteerr
  • 6. Character AArrrraayy iinn MMeemmoorryy cchhaarr nnaammee [[ 110000 ]] ;; ccoouutt <<<< ““ PPlleeaassee eenntteerr yyoouurr nnaammee ”” ;; cciinn >>>> nnaammee ;;
  • 7. Initializing aann AArrrraayy IInniittiiaalliizziinngg aarrrraayy ooff iinntteeggeerrss iinntt cc [[ 1100 ]] == {{ 11,,22,,3,,4,,5,,6,,7,,8,,9,,1100 }} ;; iinntt cc [[ ]] == {{ 11,,22,,3,,4,,5,,6,,7,,8,,9,,1100 }} ;; FFoorr cchhaarraacctteerr aarrrraayyss cchhaarr nnaammee [[ 110000 ]] == {{ ‘‘aa’’,,bb’’,,’’cc’’,,’’00’’,,’’11’’ }} ;; cchhaarr nnaammee [[ 110000 ]] == ““aabbcc0011““ ;; cchhaarr nnaammee [[ ]] == ““HHeelllloo WWoorrlldd““ ;;
  • 8. CChhaarraacctteerr AArrrraayyss TToo rreeaadd nnaammee ffrroomm kkeeyybbooaarrdd aanndd ddiissppllaayy iitt oonn ssccrreeeenn cchhaarr nnaammee [[ 110000 ]] ;; ccoouutt <<<< ““ PPlleeaassee eenntteerr yyoouu nnaammee”” ;; cciinn >>>> nnaammee ;; ccoouutt <<<< nnaammee ;;
  • 9. CChhaarraacctteerr AArrrraayyss DDiissppllaayyiinngg nnaammee oonn ssccrreeeenn uussiinngg lloooopp ffoorr (( ii == 00 ;; ii << 110000 ;; ii ++++ )) {{ ccoouutt <<<< nnaammee [[ ii ]] ;; }}
  • 10. Comparing TTwwoo aarrrraayyss AArrrraayy ssiizzee sshhoouulldd bbee eeqquuaall Condition : iinntt eeqquuaall == 00 ;; iinntt nnuumm11 [[ 110000 ]] ,, nnuumm22 [[ 110000 ]] ;; ffoorr (( ii == 00 ;; ii << 110000 ;; ii ++++ )) {{ iiff (( nnuumm11 [[ ii ]] !!== nnuumm22 [[ ii ]] )) {{ eeqquuaall == 11 ;; bbrreeaakk ;; }} }} iiff (( eeqquuaall ====11 )) ccoouutt <<<< ““ TThhee aarrrraayyss aarree nnoott eeqquuaall”” ;; eellssee ccoouutt <<<< ““ TThhee aarrrraayyss aarree eeqquuaall”” ;;
  • 11. CCoommppaarriinngg TTwwoo AArrrraayyss AAZZMMAATT HHAAMMEEEEDD AAzzmmaatt HHaammeeeedd
  • 12. EExxeerrcciissee  IInnppuutt yyoouurr nnaammee aanndd ddiissppllaayy iitt iinn rreevveerrssee oorrddeerr  DDeetteerrmmiinnee tthhee lleennggtthh ooff cchhaarraacctteerr aarrrraayy
  • 13. SSoorrttiinngg  BBuubbbbllee SSoorrtt  QQuuiicckk SSoorrtt
  • 14. BBrruuttee--FFoorrccee TTeecchhnniiqquuee 44 2233 9 6677 [0] [1] [2] [16] [99] 11
  • 15. SSwwaappppiinngg 6666 6666 4444 3333 33 110000 Memory Location [0] [1] [2] [16] [99]
  • 16. SSwwaappppiinngg TTwwoo NNuummbbeerrss iinntt nnuumm [[ ]] ;; iinntt xx ;; xx == nnuumm [[ 00 ]] ;; nnuumm [[ 00 ]] == nnuumm [[ 1155 ]] ;; nnuumm [[ 1155 ]] == xx ;;
  • 17. BBiinnaarryy SSeeaarrcchh AAllggoorriitthhmmss DDiivviiddee aanndd CCoonnqquueerr rruullee 11 22 33 44 55 66 77 88 11 22 33 44 55 66 77 88 11 22 33 44
  • 18. Binary SSeeaarrcchh AAllggoorriitthhmm  IIff wwee tthhiinnkk aabboouutt iitt ,, iitt iiss llooggnn lloogg22  TToottaall aarrrraayy ssiizzee wwiillll bbee 22nn aanndd nnuummbbeerr ccaann bbee ffoouunndd iinn nn ttiimmeess  IIff 11000000 nnuummbbeerrss tthheenn 1100 ttrriieess aarree mmaaxx 221100 == 11002244
  • 19. Is divide and conquer the ffaasstteesstt wwaayy,, aallll tthhee ttiimmee,, ooff sseeaarrcchhiinngg ffoorr aa nnuummbbeerr iinn aa lliisstt ?? 11 Linear Search ? 22 33 110000 Binary Search ? Suppose they are Random Suppose they are Ordered Suppose they are mixed-up
  • 21. Sending AArrrraayyss iinnttoo AAnnootthheerr FFuunnccttiioonnss  NNaammee ooff tthhee aarrrraayy  SSiizzee ooff tthhee aarrrraayy
  • 22. EExxaammppllee 11 Declaration cchhaarr nnaammee [[ 110000 ]] ;; Function Call rreevveerrssee (( nnaammee ,, 110000 )) ;;
  • 23. EExxaammppllee 11 Prototype vvooiidd rreevveerrssee (( cchhaarr [[ ]] ,, iinntt )) ;; Definition vvooiidd rreevveerrssee (( cchhaarr cchhaarraacctteerrss [[ ]] ,, iinntt aarrrraayySSiizzee)) {{ rreevveerrssee tthhee cchhaarraacctteerr ssttrriinngg;; }}
  • 24. EExxaammppllee 11 mmaaiinn (( )) {{ cciinn >>>> nnaammee [[ ]] ;; rreevveerrssee (( cchhaarraacctteerr [[ ]] ,, aarrrraayySSiizzee )) ;; ccoouutt <<<< nnaammee [[ ]] ;; }} What will it Show ?
  • 25. CCaallll bbyy RReeffeerreennccee && AAddddrreessss OOppeerraattoorr ** PPooiinntteerr OOppeerraattoorr IInn ccaassee ooff aarrrraayyss ,, ccaallll bbyy rreeffeerreennccee iiss ddeeffaauulltt
  • 26. X iiss aa vvaarriiaabbllee wwhhiicchh iiss aa llooccaattiioonn iinn tthhee mmeemmoorryy NNaammee [[ ]] iiss aann aarrrraayy -- -- -- -- -- -- -- -- Array called Name Starting address Memory name
  • 27. EExxaammppllee 22 vvooiidd ff (( iinntt [[ ]] ,, iinntt )) ;; mmaaiinn (( )) {{ iinntt nnuummbbeerrss [[ 110000 ]] ;; ff (( nnuummbbeerrss ,, 110000)) ;; ffoorr (( iinntt ii == 00 ;; ii << 110000 ;; ii ++++)) ccoouutt <<<< nnuummbbeerrss [[ ii ]] ;; }}
  • 28. EExxaammppllee 22 vvooiidd ff (( iinntt xx [[ ]] ,, iinntt aarrrraayySSiizzee )) {{ iinntt ii ;; ffoorr (( ii == 00 ;; ii << aarrrraayySSiizzee ;; ii ++++)) xx [[ ii ]] == ii ;; }}
  • 29. ff (( xx [[ 33 ]] )) ;; EExxeeccuutteedd wwiitthh ccaallll bbyy vvaalluuee,, nnoott bbyy rreeffeerreennccee
  • 30.  WWhheenneevveerr aa vvaarriiaabbllee iiss ppaasssseedd ,, iitt iiss ppaasssseedd bbyy vvaalluuee  WWhheenneevveerr yyoouu ppaassss aann aarrrraayy ttoo ffuunnccttiioonn,, iitt iiss ccaalllleedd bbyy rreeffeerreennccee
  • 31. VVeeccttoorr 22 DDiimmeennssiioonnaall 33 DDiimmeennssiioonnaall DDoott PPrroodduucctt VVeeccttoorr PPrroodduucctt
  • 33. TTwwoo DDiimmeennssiioonnaall AArrrraayy iinntt xx [[ 22 ]] [[ 33 ]] ;;
  • 34. EExxaammppllee 33 iinntt mmaaxxRRoowwss == 22;; iinntt mmaaxxCCoollss == 33 ;; iinntt mmaattrriixx [[ 22]] [[ 33 ]];; iinntt rrooww ,, ccooll ;; ffoorr (( rrooww == 00 ;; rrooww << mmaaxxRRoowwss ;; rrooww ++++ )) {{ ffoorr (( ccooll == 00 ;; ccooll << mmaaxxCCoollss ;; ccooll ++++ )) {{ ccoouutt <<<< ““PPlleeaassee eenntteerr vvaalluuee ooff ””<<<< rrooww <<<< ““ ““ <<<< ccooll;; cciinn >>>> mmaattrriixx [[ rrooww ]] [[ ccooll ]] ;; }} }}
  • 35. 55 22 99 55 22 99 77 00 44 After first outer loop After second outer loop Input Input [0] [0] [1]
  • 36. TThhrreeee DDiimmeennssiioonnaall AArrrraayyss iinntt xx [[ ]] [[ ]] [[ ]] ;;