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

pop assignment 2

Assignment questions POP

Uploaded by

gautham12ag
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

pop assignment 2

Assignment questions POP

Uploaded by

gautham12ag
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Page

AssIGNMEN T->J

oplaco elth caCample hoce unctten dettauation, unctioo cau


and fencticn delirt tioo a0 done o Q progam
hunctioo
gaup slatem tot hat
task
unction Declasatiop (hunctibo potoype i
unchorn, the toopi ley mst khoo aboat
paHamte and the type pauamdas
ic caled unctieodeclastatio D.
Syolasi
sLehaen_dotothype hnchien name Ldatatype yanablel, --
HLnctioD Call
uoction call statement
Jencten is fovoked te compilet fumnps to dhe
called unehionto eoceuee
x once the called funtthon is executed dhe pagam
cODtol pascs back to
Syotaag:
unton nome asiablel Vascable Q=--)
in
taguage a feleios
tekasn typ funtion nama (aamdem ist)
body f dha funtthen
3
ohesl
Retexn type- AJunetion may Hetuth a Valluea
The data type
Some case dhe data typroi be soid -itehsns
statemenl that deltoe
Yunctionbody - collee tioo
dos
Lohat
dhe Janctián ldata type YAblel,
Rame
ekeuo datatype funition
aalatype vaeiabe2,- )

statemet

HCkLaLn (aiable)i
Ecamplei
add twn
pcgtas to
#include <stdio.h>
WEUNCcILON DE LLA RATION
Pat suo (lat ant b);
fat mainc)

painy("in nton dhe

fotal - umfouol, ouma)


DEUNLTION CALL
priaf ( n Total Ld, Eatal):

IEUNCTLOAN DE EINITION
Pat Aum (tat a, int b) 1EUNCTLON HBAD
WEUN TION BoDy
output
Ente dhe
Entes dhe [Ccond ounbcY :30
Total 50

a)l Demoshat the


Cal by Refene wtth eoanpe
ohen enctioo s called, dhe calung fnction nay haxe to.
paos ome values to dhe called fupction.
be pased to dhu caled funtion: Thy
L_lall by Value To ohich.
Calting fun tion to he caled
Juntoo
T) chich addaess vasua bles ae pasc
by ha calling Junchian to ha cailed fuoctian
Y hen thl caling anchion pases anguDeot to thu calta
cal
by yalue method only 3etusn statemeot
melid value.
Betl opton oben a LOant
to modythe vale
dhe angument is to paa angumatatng cal by fent.
To Cacllcate dhat an axqunerrt k pased ceatng cal by
asteukk (e) s placed afte
pauameto licede

fo thu aqumeaty oiathor than opy ia value


focarnple
#indude sstaio shs
vold add (tat x);
iot matn ()
functiony.a
add (&num)i

VOLd add (iat Xn)

Called enction -Ld


-palntf Ln the kalul gnum in thA

Cutput
The vau um hefore calng dhe fuottion l2
Ldhe kalue called fupcthon s
h valu g numbea aptes calling ha function 12
a)aik algoritbm and examplt Jershing for convuting
chaxacdey lato lousex casea
epeed to add3ato
Mee Just
flgcaitha
Slep LiLINLTLALLZE] SE Te0
Step &i Repeat etepa ohila sIRr]|= NLL
&lep 3: TE SIR[TJ> =A' AD SIR[ T z '
SET LoLDLAh r]: STR T]+22
ELSE

SET lowtats]- sTR r]


SET I- Tt
Dese Pnge

Step 6 EX

foxample
t#include <stdloh)
VoLd mnalnc)

chan IR [1oo] looenstx [uo0];


casea C):
priatf ("LEaten the shing "

touoesst r]- sIR (r]+ 2a;


3
elue

toweut CrJ= STR (T]:

loocestor]s\o:

put (loueasb )
gulehl);
Culputi
ento dha sttng
HELlo

hello

)DemDns hat h oorkhag "Knding hl


eotdh algailhn ang
oldhout csing buill -n untien
pegzam
aumbey chaxactCE fo the staing consthutes the

&Note: blaak <paces counted a chasa elee o dhe

sthing
Al¡oithroL
&tep a Repeat step 3 chile

foxample
inctude cstdio.h)
Vold ma'nl)

tat taDlengdh
chas Sh [1o0];
clasus C)
print (n nto tho sthing
Pge

ohtle (SIR [r] L-'lo)

geltk);

Dukput
Gntor th khing
ehing length is
caluulat Hhe

palats
Lcde
taclud <stdiia, hs
at maac)

double LOdiuatea =00


double p2adiu- kaadiLs, paHea =Ranea
prily ("ln £aton dhe aceus

thecscle olt sadius alla2


println he auea
Eater the tho cacls

)plan passlng paxametey to tuntticn


Lolh otanple.
Passing axgument to unct ons ustng padtes
patnt povldes mechantso to datadeclateo
cocde
Juncttonang
To c2e
polnt fer pastng agumeat to a fuoction, the
pagamg. autdo dhe
Declase the unction paxamto4 a potntes.
degunced polatena a ha funetion hay.
pas ha. addatse as the ochual atGument ehen dhafuac
tlon i callead

Exarnple pogam te add tuo nteg txs wslng fnetion


#ncud sladio. h

ot macnl)

numl,numa,tolal ;
humbex ;
Aarg lthd", knum),
painf(n Enton ie second numbers)
sansl diknuma)
kum (&numl, Bnuml,Atolat)
painf(n Tolal: d tolal)
{ = Xa + x b;

Culput
Ente the
h &econd nnbe :3
Tolal5

Lohtch shhuchue Can be

ShucteeL and
kapw dhad malo
X
phlasephy
Thee thse methedby whech
Can be One
Janctiea to QDothtt

actual agu
-ment
enhre twcte to dhe alled

duatieo pas dhe <hct agmeat.

the
the called
acme lShructse vaniablo name)
takes dha
calted hnehoo. Dametnane
data ype fenttion
shuct type stname

Lxetstn leosprcsatan)
Pas ing irtauat
membuy

Paslng ahucturcee pasafaq dhe enae


sRuctse
tpasng he Qddseg
hehete

3Datae shutgEoaplan he syptaa delaua hon, loitiale


zatio and Access tong
sample C cocle
Shucte
set- deliocd data type that can sten e
uclatec ingaunaten tagatben.
dec laatioo
Syntaa : cwct stuctname

dala type
data type

TAlhalzation shutoeg
Some Canstoot
TOlHalzlg
to dhe DtmbNL dhe huctue
aaigalng
Syotasi
shuct shuctname

data type meobuy nama l


data type membit_nomei
Ahudvau = Scocns tant L contant 2, constant 3
shuctstuct name

data type membt nQmel


datatype MenbiM name &

whucd s h t name shudat `onstant l cons tant2 -


fxample
Hlacludeestadi'o. h>

shuct student

chas name eo];

chas DoB [Rc]:

bhuct shudent Shudl;


priay n Entes tho oll aoben i

Enteyhe aa mei
priayln
seanff"n Enty he nanae
Acanys" skudl nanaa):

"n fates the DoB:"


pia
ktdects Ddacu");
prin ln
piatf"n Roll no- 7d' studl.nollna

snoB);
painf ("in DoB 2sstud

aukput:
nter the nam Raiiha
Entea dha Jeca i Hsaco
Entoy dhe Doe:24-O8-2oo6
Studentdetauk
Roll no2 01
lame=
-Eees 4So0o
Dag=QO8-2006

Uaion dalaation fniha


UNION Eaeplatn Iho syala
-izohon with sample Ccole

& Biooilay to shuctexeA, 2union a collection vaxiablee


diyeteat data typet
at any

Syatasc:
Ualoo unionnGQ

data type var nae

3
Eaanpa
ticd <stdio. h
typealg shud foNTL
Cat

POLNI2

shuct PoLNT. pl= $3?i

unlon POINTA P2

pi ( n he ca-ôrdioales PÊ ae Ld and %d

autpd

uaed to xead data


10)TUlushate ho unthions
and slhe data to e
to
data
prouida

Lgctc)

atmpte

pfpdcl)

Banple
toclude <stdioh
Edeliae MAX ELLENAME-LENGTH 100
BUEFER-SIZE 10J4
Pot mnala)

chan nputEiehane (MAXEILENNME_LENGTH]:


Chay tagelEile Alac (AX ElLENNEME-LENGT):
ElLE
lapd Ele, ctaxgetEie
chan buyenleuEEERSIZEl;
slzet bytesRead
priay "aton theopd o.
Aanflts inputEte Mam)

átanl "stang d EieNlana):


Pnput Ele= fopen (inpul Fie Alame, "s
nput Fia zzNUL)
LCould pen
iaput

LangetEt e zloptn llaugctt leAlarn, "o);


Zelagetrzes Alott)

lacale ta

ohre (ChytaRead fuead (bubfa,l, BOEEERS1ZE, opy Ele)


20)

Jctn Cbuyen, byleaRead, langtEiL)2


3

Jelese ltapusEia)

ia aplain aceie fuoctioa oldb cOample

Reusate anetion dhat calle


A seLLSlYe

cohtch docsñot eguixe Q call


oat

" Base case


Recuss fye case
Relatable. he Make
zdentten becan
assigDed ksaluinteges fach
conctat
eaumHated
type. integen slandand the en
sca type,Leancd dato
stype cnumuated
types cpumHaded
data
Qcce anddeelasation theluahat topiaga
rclepa agotan. olh types enumeHOted
data leno oud 12)
(IZdhdháT,&y) scanf
xyes int
macn() kold
3
eke
tem:x
<stdloh taclLde
Paga

enumGation-nan
enun
CoLORSSRED, BLUE, BLnCk, GRELN, YELDw,
PURDLE

Bxamplc
tCnclude <stdio. h>
tad mato)

enum ERED= BLE BLACk= 6,GREENZ YE LLOU pURPL6,

cutpul:

BLWE =3
BLACk=5
qREEN 7
VELLOL) =3
pURPL E =
LOHITE 1S
c)Examnpk:
Ente foputEle AanmInpc
Erées tasqedEleAlarm tacgcdc

Lntes dhe tun aumbeL


36

You might also like