Progvammning nc
Yeov - 2049
Semester Yall
4.0) What is Programming lan uoge? Explain abd lov tey,)
Programming language and hish level progvammin:
ii as YN J d
fins The programming language is the officioh language
tov rong Moe wsed to atte 4 Compidey
Progyam loy the programmers. examples of progvon-
Ming languages ave © ,CAt, Tova, PORTRAN , eke.
THs used to provide sels of instructions for
computers +o exeode.
Low level programming lang e
A low level language iS a wogramming, language
had provider Wtkle ov no abstraction of Srepva-
Maing Concepts and is very close tp writing act
ual Basins snatch ons. The examplesed
low level progvamminy languages ave AsSemb|
and wradeve ceded on hd d
Low ~ level languages ave us become
proqvans wmtten in dndh can be cxafted te
muy verd fast and with a very minimal men
However they ave Coraidered Shavder to util
foccome they ae vequive a deeper knowledge
mochine langage Lt is expestat Speci
Used to develop- the Program ov ade for
Specialist hardware such ax device drivers.
High level Proqrammi lanquage.
The hah Aled aye ig W Depron my
Narquage ave \ike \Sh language with|
Words also kroun or keywords and fever Syntax
Each high level lon wend wil have ts OM Syntax
ord ket wovds . The Me A gyrtan 1s gvammey
The 4 @ xaraplea af hiq)-level YO, yar
lamquages ave PROLOG FORTRAN, LISP , eke.
Wish level lanquaje praqvam ne je exe.
cuded divechly It veils. So e translator to
ek it tromalated to machine lonquage Too tyra
Avonslatoy interpreter and Compiler ave aed . 44H.
This e aay to develop high le vel language Previn
Alo the debougy sings ation In this” language as
Ws alike, to eval language.
b. Whok iS the ied of algorithm in pro as
Write dowon an algorithm to check Nine aigln st
Number is prime ov not.
fos Algoyithn is step by Step procedure for solvi
the ‘problems vated in \gqical is colled
rovitam , Atgoviths ave. move yreese than the
Svformal jnstvuctios and do not vequive ony a
to follow. we con get o lots Af Problem anle
“nt o wey rom, with the. bralep ef help of He
oon vlna Cary be identified We ke Can
ai the step b dep cade to be written fates
the evvov. It's Yo-like ot ty aH
eye Tt is vovitten in the human a
_ Withowd the alsovithm the prabl
ood, be identified. The Syetel i ge onde
sed when to collect dota irhen to provers it |
how to Solve it and hoe fo-pr Lohod yegult needs |
fo let be presented to the wer,Algoythm:
ay) bh
2) exter a number san
2) Read ny
4)
Algovitam .
4) Stove
2) Enter a number 57
3) Read 9
4) T=a \@udeo
5) if te :
¢) Tren, 1 nv teie=0
3) Then, Count = cont 4
3) «feiss
9) ee TeTth
fo) eae Tf Count =O
Ten,
> Distloy nuwbev is prime
7 Dsthey ane number 1s nt pyme.
$3) endAa. Which of The followiry are invalid voviable ome ord
Minimum — Qyst na Row Total nana
Doubles — aydvow —Colunan-Total floor
Deserve the. tou -osie dota types along with theiy
ye and vange.
fe A vawiable is a dada name thad M be uted 40 Sto¥6
% dada value. Unlike constants tat ain erent,
duying the execution of proqvom . a voriable. wo.
different values ot different Hees duvi cublon
y chonsing a variable Name theve ave yules-
3) Te can oo ist of letters digits, and undevscore Chavadey
ii) They rust wean with a leber.
i) rt Would ~ oe AK kenword .
iv) Wnite space iS not allowed.
So, Doubles , Minimum, Bd—vowSvdve Ment
ave only Va\id.
|
|
|
|
|
|
‘Doo ype is a predefined function of C whith tell |
he compiler to set side an APproximake Amout of
Space In memoyy to stove. the values arsociaded with
€ach voaviables ~Tt also enables Compiley fo Tratruch the |
machine to perform Specific. operation comedy, The |
woanic A-fsuv dota types aye : |
\) Grav chav
A Single Chavocker can be defined on a Chavackey
(chav) type dota. Chavacteys ave usual Stoved in
B bits (enu one byte) of indevnal Stovose The quadifiey
Syned ar unshned moy be expidtly oPolied to chav. |
Lokfle Signed chavs have values from -122 424,
unsigned chavs have values between 6 ond 25s.
w) mt
Integers ave whole numbers vaith a vonge af values suppo-
vied by a particalay machine. Genevall, + oc
oh een ge
d stovare, an Mee The word Drea of machines |
one wor “t y |i ie Fant fs y
vac pial, ox 3 its) he SE? TR |
oer acters - pe c- ey Value » |
46-bit word length the Sige of mae el
Vinitted to the vange ~ 32968 to +3276 7 Chal ty 3s
to +0! 1) A signed Inteqey wees one bit tov sign end
; bev.
4S bits for the mgg nitude of the nun
Ni) Float /
Ploaki Poink lov veal) numbers ave Stoved in 8 bits
(orn al 46 bit and 32 bit Machines) with 6 digits
Precision }oatin Point nursbers ave detined Sn ce. by
the keslooavd flodd. When We accuvacy provided by a
Oot Yumbey is not sufficiew , the. tye double Can
Wed Jo define the Number. the vange Af Hook ts
S34 E -38 te 3.4E438
Aw) Double
® double data pe Humber Uses 64 bits ins 9 fre-
Cision of 34 Figs These ave also known as doub'!
Precision Numbers Remember The double, vonges
from 1-TEB-WsE to 4AE +302
b) What is enty cnballed and ex
at
Write a pyo ‘t controlled \o0p?
ae Y " tD print follorsigg fadtern.
4 9 3 4
to 2 8
4a
1
bss, Ontry Contalled loop os a AUPE cf loop in whitch He
Condition is checked fist And then oftey the loop
body vs executed. fov tap ond takile lop Folls in tus
colegoyy. Tf tre tal ontton is true he long be
isoall be exeuded otherwise, tne \oop is terminated./ ich condition }
Exit conbolled teop is aloop in rae = De
checked aft the execution of the ee
whe leo is the example “THe Suen it the deat,
be exeaded at least once 0 ™ |
Condition is ue ov -folae.
Program !
ainclude 2 stdioh >
+E include Z Conio-h >
verdes Voidmdn ()
Lint 155
for (Vaystzes ; TH)
x 5 t+)
tov (f= 644 4786467 5
x
Printf Cy 2d” 4) 5
Printt (eAn") +
y
Gtr dd 5
5
da) Write a vecuysive progyam to generate tne fbo-
nacct series vets N tern.
A function toh colle itself ws known os yecursive
tum ction amd this technique iS Know as vecuion in
C Progiamsminy Recursion 1s mor ol ond requires
vowables Which make Program clean. Pe can be
vustd 40 veplace Complex nestivg code aliviieg
Ane Problem into Game owllen ¢f! Stab by pesAP includ Zetdio-h >
Int Fibona cei (ime i)
Main ()
Rita | 7
8 (Yd! dndjy | "
ew o Rbomacel. sees )
for (cea jccenj C4 Hn)
L printf Czar", Fironaci(i));
thas
4y
veturn 5
a ona cei (ind vn)
LAR Un ss0
yeluin 0}
ase ih (peat) : ' :
cao i (naa) t Fibo nacei (n-a)) 5
veruin (Ripon acci (nl ’
4) what is on ow Q WAP to enter values in 2x3
Ovder makrix and” compute the sum of odd elements.
hws An avery is fixed rSIqe Sequenced Collection
Clemenks of the same dota type Te is simply a
Grovging of Vike type. doka «fn “its Singplest form,
can be wed to vepreaent ot list of
le we Gn
an ay
Numbers, ov ANSE of named. for. ex,
wee Ono 40 list Tne employees in an ovgoniption
Program:
Hrinclude 2 gtdio n>
At include 4 conioh>
Void main |
int mot C3J 03] 15, gum:
Drintt (" entoy elemenks of adv;
fr (Feo; T2385 ty) 7
q .
for (J2o;j 43st)Seanf ("4d ", genot 401) cay) 8
Boast CmatsCHgCi he?
§ if (mob CUICI] 122727
Lsum = Sum + mat sci;
y
y
‘ ' .
printf ("The sum f odd elements in mothri »
ts ded a cum)
jenl);g
j
4a) explain any + functions that ave veloted to String.
The functors velated to stivgs ave:
1) Star Streak () function
The Stveat “function joins two Shings tyjether. TL tale
the following form:
Streak (sthhg 1 Strivg 2)
String! and Stu ny Lave Crovacker avvags
2) Stvomp () function
The stvompt) function compaves +00 strings identified
by the axgurvents and has a value o if ave equal
Flos ae nok , ib has te numeric difference betw?
the fiyst non matching Chavaclers in the. shings Tt
takes the form:
Sty emp CString 4, stig 2)
3) Strepy C) function,
The strepy function worka almost like a trigg -aastyt”
mend x Tt takes the fotlors) mm.
stv cpy (Stn 4 string 2) |
amd ats contents of Shiny 8 foshing tBs
4) Teen Ranelton a and vetuine the numbey & j
. es the form
Chavaclers in a shiny. ve
N 2 Stvlen( String) | . .
Wheve n is on te 9 variable , which yeceve, te
Value of the lent of e Shing:
S) Strlwvd) funchon: .
Et Me fundion coverts the string to the lowevcoye
TA takes the form
SEY bay ( stot) ‘i
6) Grey Styyey () fundhon:
The function veverses ‘the sting allphaloeli My
TL fakes tne fore
Strvev Ustring) |
a) Stncemp () function : -
The -funchion is the. voriakion A stomp Tk hag 3
Pavameters ax Muatvoded ,
Strnemp (St 31,n) |
this Compoyes the lept-mast n chavacleys & 84 tS?
Ond vetuns
b) How Can we vehun multiple values from a -fanction?
Sxplain with an approp viade exawple.
Return Statement con return a sluyle, value. po weuw
Mut ple valves coh be, vehurncd from dunchons
voivg arguments that we Pass do afin Chon The.
Ovgumrents jtrat aye Used to Send ord tnformahion
Ave called oudpd Patawelers The Mechanrgn of
Sending loa ck indloy mation Horrone Anvougn onguenls
is acheived usi whet ave nou
no the
addvess operodors and
Indivechion oper ator #).80M ae wy intg ink # Sd td) 5
ude, < 7
Void rotbagection
main (18 3, 4}
Int wero gett ‘
Modhope vation cag dds 3,4) 5
Drink § (sum eed \O-STE SN
Cink a ink bind sun inh ad
Qe waodvopen aston
{ asum 2ate5
% df = a-b 5
7
Me variable #suma om ‘
con ume 4 Sf aa er
decided dead os the ink , Hae Co"
of tt type dada-
‘ 4D pass
Sa vanat ic furchion P ped worite @ Progvam p
‘one. dimevsionn| avery te Pnction and aispey ‘
avo in that called “function .
A funchion Pro tobype is a function dechavadtion
that specifies He dada types Fits ayjunends
in the Pavaweky list. Tie compiley uses the
information in a funchton Protope to Ensure
thak the covvasponding function detmation and
ak covvesspondi Buccion Adeclayation wit
Omd coy wit the scope, Wy
Contain tue covvect Iuvaig ft etre
Oo
Java meles and Hot eoch aque or paramekey
ts of the Corveck ets data type. Prototypes ost.
Syn to'chically distinguished flom tue old style
Pancho decdar ation. style
& FAL awe known O48 Pdirderg:
bles Since. they ave
poivt to locahtonat include Z stdio-h >
main ()
X Hoos tavgeat {4toak al 4,
Coat vaiue( 4 S LS HeTS IF
Pring £ (Zen, lavgeat uals
Hoot lavgeat: Utoat al
int);
ot,
5
J jiwn)
£ int t
Hoat ann;
max 2 alo)
Qt 2; Tens te )
if (max z ali)
ma att];
yen (axl 5
») What ave fmetion call by value and colle by veleve-
nee? Explain tre with Suitable examples.
ao Rinckon vith vebuhand without velurn can be colle
to aig the diffevent Syntax.
TiVdata is prased by value, the data is copied
dom the vaviade Used in by example matn() to a variable
used by the function. So,7f the doda poased (that is stoved
rato ee a te
in the. .
eae ‘J ‘J voviable vised inside
Program wsing CoM by value
thinclude
geton() 5g
5 .
Void Swap Lint, Trdg) 5
J ink temps
temp =n :
weyt
= temp : . '
Print CVn Trside function a and b ave Id ond
mip g
4
TH data ic poased b; relevence a Pointer to
the data is copied instead et the actual variable |
At is done in a call by a value Because a pointe i
Coppled, tf the value ab thot pointers addveas ts
chonged im the flnchion the volve is alSo Changed
in Moin),
ae (nclude <8tdio.n S
at inckude Zanio.h>
void col ky reference, Cnt oy)
Print ( Ntraide Povetion D> 4d before adding 10:
An", ps
Ug) + sto ;a er add ot
print Draide focton gm a of a
An" ay) ;
j
ind main ()
Lint b 240)
Prndf ("be vd before
cau velevence (4b) 5 ; ;
Dri U' be exd after tandion.\°", bo)
yearn 0;
5
6a) Whok is a printey variable ? How can Memoy &
& varlable be initialized Agnasically 2 @xplatn
With Suitable exampe. :
_tes A pointy is 0 crank vahose volue is the addveas
of another variable. ve. divect daddveas of the
memoyy locadion .Vtke variable oY Constant, you
must declare poindey before val ib to a
Vomoble addvess The general form Aa poi
variable deo dechavation ts
type avave-name 5
The exact sige af avyoy iS Unknown until
Hoe compile time -ie. time Yohen 0 Compiler
Compiles code vaviten in Proavammi lang 2 two
a executable form. Te sige aR avy qou Wave
declared initially Gan be, € Sometimese Se (Or
vequived. Sy D Ramic memory allocatteon allows |
a Pryvam +o owtain move memo: space , akile
rrunning ov 4 velease space. ahem ‘no space. is
yequived.
Memory can be allocated by Rae a aa
for “maemo allocakion" ,
Pty = Coot types )roalloc.( byte - sty)
function \n",b) ;“he oe Stands ov * Contigews ablocatis. »
re aiesence, peween walioc () ond Codloe (yt
Xrod , malloc ) adlocades singe teroc of menor
whereas cobioe () abocakes multiple vlock of
memory each of same Si and seks OW bytes
tb qed. ;
Pry =Coat-typed calloe (ni element- sige)
Create a studwe naned emplayce With She.
tyre membes NAME eid , adders and ender.
Structure need to read \wformoastion fr Si emplarg
Write. oh content ie Me file into-dat and
wohiije yebriexing, display only one te tnlormodion
Ahose employee whose addreas ig “Kadtnmandul!
akindude
at include ZStdAlioh>
Mt main ()
Tat aS SO}
stick empleyee §
char name Cs0 1;
char id L109;
choy addvess £20] 5
ink gender Cio;
Y emp (04;
@ PILE * Ppty,
fpt r= foper CON tifa. dat '" wh +”) 3
CF (Apty = = NULL)
x
Prinkt ("Nb VE Evvov) File does nat exists 1);
exit (1)
5
BPrint Emplqyee's Detail”);
Vv Unt feo ¥cas itt)
LT print $ WAKE Record fed wn", (1H)
Print $ OY rome s\t" iy
Seon § Ce" emf t] name):
Print ¢ o Tove");
Seont O43", emplid. ia):
Printt Gender : We
Scan $ ("s3", emp C¥J. gender);
FPMiM EE (4 pty SILT SAE SNE F-8\N", empl),
name, emplil .id, empli].addvess ,
emi}. gender) ;
vewind (ftv):
Prinef Un Seaplegee’s Report (Living in katnwardk)
oe
Fov Link fso1te a‘ ite)
x tsean ¢ (pty “fog aes slo S429", emp GL name,
emplr3. id, empl Laddvess emo lid genden);
rf
(Streme Cemtt J address 6 kathmondy" ) 220)
Zvi U8 ERC Cord Numbey 4d WW" THAD);
Pind CONawme : \trres\nv, empl name) }
Print CED *\UTSWnt, compli}. td) |
printf (" Addvess « Vt ‘T8\0", emplt }. addvess))
Print FC" Grendey :\ta- s\n! vemplt J 1 gender )
a
felove, (4PEY) ; return 0
yJF. Write hort notes on
4) Unions
Unions ave Concept purvowed from Stu du ves
And Anevefore follow the same syntax oh i
Stuctures.Hesevey tere 5 a wofor atest distinction
between tem in teres of storage: In Structures
each membey has its awn storage location,
eamevead AU the members of 4 union use ae
Same location. Tis implies thas although a union
Moy cordain many memisers of different types,
it Tan handle onty one member at Otine Tike
Stwuctuves ,a Union can ve declaved wsing the
Keyword union ov fellows :
Union Sten
Rint ™;
Mood 4:
Choe ¢ 5
Code:
yi
Ths detlaves 9 variable code of Type union iter.
We
© union contains thee Members each with a
Bilterexd dato type Howevey, we can use on
one of them ah O time Tus ts due to the fa
Hyod re onl On€ tocahion ts allocated for
union vorobte , Wes pecki ve of its sige.. y
2) Macros,
A mace is a seament of code Wich is replaced
log the value of Macro. Macro is defined b
4t define divechve. Tere ave two ype of Maciras
4) Ologeck “like, Macros
2) Aunction like Macros
Object Vike macros
TRE objeck-like macro iS on identifier that is
Neplaced by value. Tt ts widely used to vepres-
ent numeric constants . or example!
ae detine PT 3.14
Here, Pr is the MacTO Name Which Will Ce
Yeplaced by the value 314.
Runction Whe Wars
Te dunciion Uke macro look like function
COM. Por example,
ae de fine MEN (Ab) (Ca) Z Cb)? (a):(b) )
Hore, MIN ts the MAO Name.
The c defined macros that can be used 1
© ave: _.
oate , TIME PILE, LINE, STDC .#-
Yeov. 2049
Semeatey - py
Lag a tunel pager ong
pte and contranst Hj9h level language 24 Tov
evel language... ;
fa Ck called a Shuctuved progamssi longeaye eat
dD solve a lowe problem , c programm mg "se
divides the proiem into Smalley shuchuvod bl oo
vakieh each of whith handle o pavtioulay eS pOWSibilfh
These stucruvad bloda ave decision makin a tie
‘Tf -elese , Stitch cose ; vepetitive blocks Wire for Ne,
LoHile - loop j veh swovo uti nes | procedu ves -fanchions The
Program wihith golves the entive problem 1S 4 colle-
Chon a such shuctwwah Woda So, C can be called
Stwuckuved Programmi la Mage .
The difference between the hah level louguage
Ond low level Nona e gre
High level Language Low level Vouguage
4. High level languages Oye 4. Ft ts Low level lon
ugye is
Sivnple and toon “4 difficult to we and
Ond un derstand. undevstand .
2, Tt hove minimum code, 9 Tt ig iff cult £2 Vemenker
Symivol and vules code tor every twig
3. Tt is not based on Computey a Since, it . depended i
So there, is NO need to know Machine. compute avdhite
Computer avdnritectuve , ture shoud be known Wy
Progranmey.
4. it Vos better Prog TOM wai
ATL hos be
efficenty. "I tev machine
Hicieness)
fu
vith, and Mow chave
Wh wean © ‘
w rn then D4 Wow chave te find Ph posi,
vA
ndvome ef gen nurtley for Solving tye
uve
gor cep hy proses oa
Problems vovitien in logical ‘on for x m
Algorithm 3S ‘the theovitl col prezerdation ee x
FP solving Provlens and Ont Pte 4 i oa
Phe sane alqorithes, when 1E'S a ati
graphical endotion 4 it is Known 08 4169 cha,
orithe one doesnot need to foltoy
vomte in the Wi Ane PYQYammey
le pidovial
40 the rule
ohile. wnt
any yule , just con
crderstonds. During The Plovchav t
Yepresentation must be acearhing
Algorithm
4) Stayt
a) Sntey a number oa
3) Read number 9
4) Number =
58) WHE 4 is not O
6) vemaindey = n‘fel0
4) veverse = yeverset10 + vewainder 9
g) Nn b= n/so
3) LF number = yevese
4d) Drink ‘word number is palindyome
53) AK, Priv numley vs not palindrome
42) End
Prow dnave
EeVemaindey = n=l JO
Vevenge = veveyse #10 +
N=en/so
vemaindey
Dis Play the number
ig not palindrome
oa wey st is mecessay 4o have a knowledge. ef dota
in Gregan) plein a data ure available in C.
eo mae ts predefined function af C which yell
© My fo gek axide an approximote arouwd
of space in enayy to Stove ‘the values A&soc
with re ‘ovicll Tt ako enables compiler
wébuck the Machine to perform specifie operation
covvectty 5
5 chav
) ® single chavackey can be defined a3 a chavacter Chay)
dodo chovackeys ave veal Stored in 3 bib
Ww
eo byte) of internal store “THE qualifier si". it lied to chav. si
ov unsigned may be explicitty ape ee see oN
bole Unsigned loravs have. Valu' eee
Sgned_chows wave. values from - 4 :
w) Svtwey types
u oe tahole numbers with a Yange of values
Supported by a Rar tculay machine . Grenevadly | ":
eXS occupy one word of Btovage ANd Sivice™ Hie
Boyd siged af Machines var’ (4ppicalty, 16 ov 92 bids)
ane sige Ron inter Sebinds on The compuley,
a) Poot point pea .
Hoakiny point ao veal) number aye stored in 31 bits
foo 16 vit ond 32 bit machine) , with & dues af
Precision. Ploating point numbers ave detin ine
by the key lboavd Opiood « Lohen the ACcUvary Provided
by a od Number is nok sufficient, th pe
double can be used to define the nuwmbey We vorge
of float is 24 -BE to 2.46) aBs08 28
te) Double a
A double data Ayre nunbey uaes 64 bis ay
a precastey ef 14 ARyits ese are also Known as
double precision numbers . Wie double vanes
Aron - 5.7 £ -308 te 4-FE +308
v) Void
The void type has no values. This & usually wed to
Specify THE type of funchtova. The tyPe tundion
iS Said to be void when it does not veturn
value fo the calling Rinalion, TE can also peg ee
role. oR a qenenic Fpe , meaning that iE can repres-
ent any the othev standard types.
sy
PeA
A
Db) hal is an awoy write a © Pregvm oe aa
Pm natural muadther i oe oy qven nuwte,
Smablest Numbey from at oS
rear F Aitection a4
As An ow is Lxed sige Seq _
clewwentl of the ae dota - Rea _ ot
Joupivg of like € ere 1S 7 4 40 ts
Sidpeat UR, can be vies te
a Vist of ee ov avtist AF names -
at include Zconio-h>
Voidmain ©)
int NC s90) )
Pant C'nter Me 150 numbers’
for Fa $5 F2ssop Itt)
Fant Ord, &utid);
4
S-=*01) 5
foy Cis d tes100 5144)
S iF Ot ‘J 4s)
i = KCT7F q
4 .
pynkd (Tre srtallat number from the list ts
a" 8);
jerch :
y¥
3.4. Detine Recursion. WAP to find & Sm of mvotont |
Numibey wsh yecu YSIOM) +
fea A funckion thot cabs itself me
function and tis tedanique | move. elegonk and y
lin ec vararring. Recavsion * s ee
lees ‘ i Scadion,
| wives Hy voridJoles ro edined nedaavsion cay
| Foc: hoa ween eae es as nesting code b
| be used to veplace proc i
| divi dt es rote tS ae
Sulo-type. Meo, it is diffielt fo dewey
ead ve cursion
is known O4 YE CURVE
own Os VEC oy
Prog vos code:
ab Inchude Zetdioh>
int add number Cint nl 5
int main C)
yt num), . : ")s
printf C" Ender a positive in 44aeys ,
seanf (Std Aenum) ; ;
printt (sum od”, addnumtoers (num) ) )
vyerurn 0)
ink addnumboers Cint in) §
g
i CoE oO)
yetuny 1 taddnumbers (n-1) 5
ewe
yeturn nj
5and nested Th hye
by Differentiate. behoeeh ee example
Statements vith
Neastedtf ee
4.The expvession meade f
State decides Whether
med AIO Tenens iwrich care artory tre
to execnte the
Inside. f block or undey
Age wlock .
“We can hove ranttigle Hf
Stolenend poy matiple
Choice, of Statements
. TP stoderrent a
ingeger ,chavack r, ol
o Mak apoink type °Y
bobdlean ‘tye.
. Th-elge Statements ches
8witdn
j.cte enpresion Trside
a swith etodement Aecigy
giver ro exe ote:
pe iy guoitdy We have
raw ple cnnices of She.
werds for One expression
3, Sotto etadoment only
exevaluates Chavacker ov
an integer dototy pe
4. Qwitcth cheoks, only tor
for Quality as well od for equality:
\ggical expression.
eg.
srinclude
void Main ( )
Lint num o4
ef Cnume to)
£ sf Cnums cs)
S prind “the value is Adin,
mum) 4
coe
£ Prins FThe Naluels qreakey
tron >0")* y
gerch ()
5
Ss. ej.
at Mclude 4 Staia: h>
Hb include Zconio-hS
Voidmotn ()
Sivd BES
Suite (m)
L cose ‘4!
rrinsf ("
break 5
cose'S!
Pink? (value iS
byeak *
cose'6? 6S
pring fC ualue SS 67?
breaks
default :
Print ¢ vvov”
break *
geben (1s
y
)
‘ . ”
value is 4
s");
5wyeherence
Sa Sapam coM oy value owd cab 1 ey f
ve iv i?
Baer Ainchion with vetuny and with
age
Caled 40 an ane dt event "
TY dota %S posed value the dota is Copied
Aro the vortolele used tm for example man) to
Ahe function 10 H the doty
a vowiable wed & f
Passed that is A pebag tm Hue fuwction variable) is
Modified inside ane_fanctton , THe valuetS ow
changed in the variable used inside the funeHon,
Program using col by value.
at include < stdto" h>
At indude
void cod lay value Cnt »)
SJ privet Cinside Ayachion ¥ ya \eafove adding 50,
eens
INE Mmain() ©
LQ tnt O2105
ee Re Lea wefere ination We “);
Carr oy Voluc(a) 4
yearn 0 }
Zz
CoM veference
TH 4 is passed PY we ference A pointer to tue
dasa is copied instead ek the actual vavtalole. +
is done ra cou Wy Value. Becaswe a poinder is
Copied « uf the value ak that pointes adders
is changed im the funchion (the, value vy Wao
Crangeda i” nmoin().
4 include catdioh >
ord cad 4 vefovence. Cimt 4 y)
x anunt (8 Iuarde. Jumchi on ye ha before adthing
do \o" Ay);(Ry) F =10 |
pier f (Ufnaide function yoy after adding 10.9 49) j
4 |
thse |
i 210)
that (nbs «sd, before, function \w’,b))
Cod by} vehevence (410) }
pant POw end odtey Fanctton, yn”, ) 4
return 0} :
5
4.b) What is DMA2 WAP to find the sum of S numbers
Supplied hy wer using DMA.
$s DMA is dynamic MEMO alocahion. Te exack
arg o& ay ig unknoun und) The compile. Hime te.
Lanes time Ghnen a compuky compiles code vvitter
ina Programming Loma \who a exeodo. He fom. i
The size of anv ou have. de claved initially Com
be gometine nw Picient and Sometimes nore thon
ceived “DMA alins Prayan to obtain more ne
space wile vunning orto Yeleose. Space whan no
apace is requived =
a+ ude ZShdiio ih >
at inchde
ind wotn () &
Jivtn,t #oty Sum = 0 5
Ba nes
Pty ~ Cinta) malloc (nk sgeAGrt) 5
sh (pty < Null)
J
privat (Seve: \ Ce not alhocated.” ):
ext (0) 5 a
4nye
Print {Unter elenevts G ovvoy * = )5
ov (Fe 0 phen ttt
Xgeant Cord", Pt Hi)
Sum + 5 wer at) )
4
Print f (sum = spd ure) 5
dyee (ptY) }
ver 0 |
5
St) ine ae
Sb) Differentiate’ oe na awk union. How the member |
ef stmckute ore qascessed 1 Show varit wait example
Union
4 wnjainer 3 Union ts alse asiotlay |
dedined ‘ir CP Stove data Kind of container in cushith
voriatles of different 447e and con aso holds the aiff. es
oko supports for the ev vavialdes aly '
dekned variable storoge. defined vow
2. Structure in © Is antevnally a.while cose Union mem
\mplenented 08 hod there gs adhocated only te one
Seperake Meo) fabedel loca member having laygast Sige
Aon is “untied each ‘ped wrong ah) other in varios
ond que Gawe loCodton Is bel
ge shoved among ost dined
3, Shuck stud -names 8. Union U-name J
ie ae pe element 15
type ele rent 2) “Pjerctenent'?
Nea.
4 voriable worable 2-5 4 vovidhles ovale 2, —
A) mudtigle menloess con be 4
ak Oni en
iwnti ged a same ‘time ae a ie ori
ead a timeAcceadng the members af Stature
eee af a Stmchuve Com be accenrd wilh
the help of -Wot) opevotov. The 3 riox for aceadsin
tne members of the stwchure varioble, is od folly:
Styuct_vowioble -numbey
Stu ck employee el;
eh. emp.td
Aename 5
EA. Solavy ;
6a) What do you mrean by selechive and vepetttive
Stasemend™) wey do ‘G. need break and continue
Statement.
Selective ctolement ig the sohenment Which \dps
to decide to choose 4 me appropriate option
among others in the pregrammirg pov. eg. re
Bote Dek, svatich stodemens .
Repetitive stodenent is the statement Which helps
to decide nov long the Same task § to be conhi-
nucd oud also Welps to continue the toa wnti)
Vt meets the uses need. The examples of the
Yepetitive Stotemenk is do while toap, for loop ,k.
The oreak stoskouewss ends tue loop wamed iate!
when it ts encounkeved » Its syntax iss. boveak »
THe break Stoterment ie aderast wed
poith Th -- GbE Stabersend inaide The 160P. Break
stojeriend ts necessay, to end the loop 0 Avere
ig & Condition When the {oop should, be breaked.
The continue stabemevt skips the current
ikevakion of the loop avd continues vith the newt
iteration Its syntax ts cordinue; °
Zt is also Away, wed with ef else stotemet.
Continue totoed is necessamy when We need 40
pevtorm certain 403k Only ow a certain vequi-
cement, mets be we Weed to continue (orp -b. WAP 4p generate oN prime numbers rom J 40 24
ae Tnclade detalles hd
AE WUude 0}
ach;
b= temp
Paine { C0 inside excha
Me dand 1d a, 1b);
vod main( )
ce
tae 00PzS0, a-sa,; Ady, Pe) 5
Prinkf Before exchange J. om d
Cha Chan; "9
Drint E An Aber exchange yd and Id iP),
yo 5
as on ay uneuk instead
Wh sinker
i 2 vavia Ke ar ne addres of tHe voriable
‘S Porsed instead af the value. Se ov Chowse
Made ay tre funchion vaing tre Polwer iS Ferra
ee ge 4 of passed Variable
They Hehmique ts Known 03 Call by “reference inc
Tas tyoe of fumcien Call te address f voraly
Ove. oes to function instead of «chal values
ot vowable.
Exomple
4h include
Void thane (ind ta mt *b)
J jw temp )
temps 4a.
xo eb,
to = temp 5
Prvinet ( “\n Inside exchange tad 18"fate);
void rain
Sind Pa)
Privit ("Before ercronge 1d tl gt p,q);
oh
Horse 122, Lg)
Pe L Te Boley oyey ' j
. crchoe Wd py gpd)
aetoncn At vd 241-4, )
y