eLab1.o C Programming Sessions 1. Input and Output 2. Data types 3. Operators 4. Control and Looping Statements 5. Arrays . Strings !. "un#tions $. Stru#tures and %nions &. Pointers 1'.Pra#ti#e Session S(I)I %ni*ersity Learning Centre eLab + 1.' PDD ,A- 2'1! 1st dition
Course/ C 11 Sub0e#t Code/ . IO 1' Snea got a sin sol*e it te to operation#63 operation lnput de#imal pla#es. Sour#e Code 7ln#lude 8stdio.9 int main: i lnt a; #< s#an=>?d>.@a:/ # 6 a< print=>n#6?d>. #:< #6a/BB#6#a D print=>n#6 Bod>; #: #+6a
n#+6Bod>. #: C6a
n#F6?d>; #: #B6a/BB#6#Ba print=>n#.B6?d>; #: # ?6 at BB # 6 #?a print=>n#Bo?6?d> retum '< l Sample Input 3 Sample Outpu #63 mud; G2H , O (esult us; Program J * t
gle integer as an input ; and er tasK to per=onn all assignment operations in it te gi*en input . Let us elp er to lloing #onditions met; o Per=orm ; Assign an input te ne te *ariable and display %sing addition assignment #6#3: %sing Subtra#tion assignment operation %sing di*ision assignment operation %sing modulus assignment and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 All tet in bold #orresponds to input and te rest #orresponds to output. 2 C:< > IO 1' > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . IO11 Mrite a program to #al#ulate area o= a #ir#le lnput and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output Sour#e Code 7in#lude8stdlo.9 lnt maln: N oat radius; area< HC$ll=>Bo=>; @radius:< area 6 3.14 radius radius< print=>nArea o= CQtCQ&RBo=>; area:< print=>nArea o= Cir#le/?.2=> area:< retum '< : Sample Input 2 Sample Output Area o= Cir#le/12.5'''' Area o= Cir#le/ 1 2.5 (esult us; Program > IO 11 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ .lO 12 Mrite a program to print te ASCII *alue o= a #ara#ter Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude 8stdio.9 int main: l #ar #< s#an=>?#>; @#:< print=>ASCQl *alue o= ?#6?d>; 8/. #:< return '/ l Sample Input #
gle integer as an input ; and er tasK to per=onn all assignment operations in it te gi*en input . Let us elp er to lloing #onditions met; o Per=orm ; Assign an input te ne te *ariable and display %sing addition assignment #6#3: %sing Subtra#tion assignment operation %sing di*ision assignment operation %sing modulus assignment and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 All tet in bold #orresponds to input and te rest #orresponds to output. 2 C:< > IO 1' > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . IO11 Mrite a program to #al#ulate area o= a #ir#le lnput and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output Sour#e Code 7in#lude8stdlo.9 lnt maln: N oat radius; area< HC$ll=>Bo=>; @radius:< area 6 3.14 radius radius< print=>nArea o= CQtCQ&RBo=>; area:< print=>nArea o= Cir#le/?.2=> area:< retum '< : Sample Input 2 Sample Output Area o= Cir#le/12.5'''' Area o= Cir#le/ 1 2.5 (esult us; Program > IO 11 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ .lO 12 Mrite a program to print te ASCII *alue o= a #ara#ter Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude 8stdio.9 int main: l #ar #< s#an=>?#>; @#:< print=>ASCQl *alue o= ?#6?d>; 8/. #:< return '/ l Sample Input #
Sample Output ASCII *alue o= #6&& (esult us; Program > IO 12 > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ .lO 14 (am as a popular mats tea#er; e ga*e a 4 digit number to is students as a assignment .Te as to identi=y ones portion o= gi*en number. Please elp is students to identi=y and display te output/ Input and Output "ormat/ Input #an be an integer planation / Let us say ram gi*en number is 1234 and is student need to identi=y ones portion is 4 Sour#e Code 7Qn#iude 8stdio.9 int main: N int num.digitAtonespQa##e< s#ant>Bed>. @num:< dlgQtAtonespla##e6num?1'< print=>ne Digit at ones pla#e o= ?d is/?d>; num;digitAtonespQa##e:/ retum '/ l Sample Input !2 Sample Output e Digit at ones pla#e o= !2 is/2 (esult us; Program > IO 14 > as been su##ess=ully ee#uted
#ourse/ C Sub0e#t Code/ . I'15 rite a program to sap to numbers using a temporary *ariable Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All oat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude 8stdio.9 lnt maln: l lnt ; y; temp< s#an=>?dB9d>. @; @y:l print=>Ue=ore sapping/?d ?d>;;y:< temp 6 / 6 y/ y 6 temp/ print=>nA=ter sapping/?d ?d>;;y:< retum '< l Sample Input 5 4 Sample Output Ue=ore sapplng/5 4 A=ter sapping/4 5 (esult us; Program > IO 15 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . IO 1 Mrite a program to sap to numbers itout using a temporary *ariable Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 int maln: l int a;b< s#an=>?dB9d>;@a;@b:< print=>Ue=ore sapping/?d ?d>;a;b:< $ 6 ab< b 6 T VD/ a 6 a + bi print=>nA=ter sapping/?d ?d>;a;b:< retum '< : Sample Input 5 4 Sample Output Ue=ore sapplng/5 4 A=ter sapping/4 5 (esult us; Program > IO 1 > as been su##ess=ully ee#uted
#ourse/ C Stib0e#t Code/ . IO 1$ Mrite a program to #on*ert "areneit into #elsius Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#iW#ation All oat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdIo.9 lnt maln: l oat t;#l/ s#an=>?t>;@t:1 #l 6t + 32:B 1.$< print=>B89O.2tC>;#l:< retum '/ l Sample Input ' Sample Output +1!.!$' (esult us; Program > IO 1$ > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/
. IO 1& Teera is a #ute little gal o= age 5 years old; se ad one piggybanK to sa*e money #oins:. Ter piggy banK got =ull and se as e#ited to er sa*ings money. So; se #lassi=ied te #oins o= its =olloings types ; (s.1O #oins; (s. 5 Coins ; (s .2 Coins; (s. 1 Coins. -o Please elp er to #al#ulate te total amount se sa*edX Input / total number o= #oins #olle#ted on e*ery #lassi=ied type respe#ti*ely (s..1' Coins; (s. 5 Coins; (s. 2 #oins; (s.1 Coins: Sour#e Code 7Qn#lude8stdlo.9 lnt maln: l lnt num1O;num5;num2;num11 =loat total< s#an=>?d>;@num1':/ s#an=>B89d.@num5:< s#an=>?d>.@num2:< s#an=>?d>.@num1:< total6num1'1'num55num22num11< print=>notaQ amount In te piggybanK6?'.2=V;total:< retum '/ l Sample Input 1' 23 43 Sample Output otal amount In te piggybanK63'!.'' (esult us; Program > IO 1& > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . IO 2' Carmel is an sopKeeper elp im to generate te bill amount o= an item gi*en its Yuantity sold ;*alue ;dis#ount In ?: and taln ?: Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude 8stdio.9 Int main: i oat totalamount; amount; subtotal; dis#ountamount; taamount; Yuantity; *alue; dis#ount. ta< s#an= ?=>. @Yuantity: < HC@ll=>Bo=>; @*alue:< s#an=>?=>; @dis#ount:< s#an= Bo=. @ta: < amount 6 Yuantity > *alue/ dis#ountamount 6 amount dis#ount:B1''.'< subtotal 6amount + dis#ountamount< taamount6 subtotalZta: B1''.'< totalamount 6subtotal taamount/ print= >nUill>: < print=>nuantltySold/?=>; Yuantity:< print=>nPri#e per item/?=>; *alue:< print= >nAmount/?=. amount:/ print= >nDis#ount/+?= dis#ountamounl: < print= >nDls#ounted otaQ/?l>; subtotaQ: <
print= >na/?=>; taamount:< print= >notal Amount/B9=>; totalamount:< retum O< l Sample Input 2' 3'' 1' 12 Sample Output Uill uantitySold/2'.'''''' Pri#e per item/3''.'''''' Amount/'''.'''''' Dis#ount/+''.'''''' Dis#ounted otal/54''.'''''' a/4$.'''''' otal Amount/'4$.'''''' (esult us; Program > IO 2' > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . IO 21 Mrite a program to #on*ert a =loating point number into #orresponding integer Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdlo.9 Int main: =loat =num< lnt lnum< s#an=>?=>;@=num:< lnum 6 lnt:=num< print=>ne integer *ariant o= ?'.2= is6?d>;=num;inum:/ retum '/ l Sample Input 12.'1 Sample Output e integer *ariant o= 12.'1 ls612 (esult us; Program > IO 21 > as been su##ess=ully ee#uted
Course/ C T . IO 22 Sub0e#t Code [i*en an input as integer to te ma#me e need to get te output o= #orrespondmg oatmg pomt number lt =i*e dlgrt a=ter de#umal points. Please elp Qm to rQte te program tat satls=y te output Input and Output "ormat (e=er sample lnput and output =or =ormatting spe#iW#atron All tet Qn bold #orresponds to mput and te rest #orresponds to output Sour#e Code 7in#lude8stdio.9 Int main: =loat "num<
int Qnum< s#an=>?d>.@inum:< "num 6 =Qoat:inum< print=>n?'.5=."num: print=>n?d>.inum:< retum '/ l Sample Input 12 Sample Output 12.''''' 12 (esult us; Program V IO 22 > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . IO 23 \r."tigt is an englis tea#er ; e got tasK to to #al#ulate a students result based on input o= to eaminations ;one sport e*ent ; and tree a#ti*ities #ondu#ted . Please elp im to =ind te result o= e*ery indi*idual se#tion a##ording to eigtage[l*en belo: pro*ided by prin#ipal tat results to eam per#ent; sports per#ent;a#ti*ities per#ent and =inally total per#ent tat sums all indi*idual result it =olloing #onditions met Meigtage / ACl)QlSMl[TA[+ 3' SPO(SMl[TA[+ 2' ]A\SMl[TA[ +5' otal / ]A\SOAL out o= 2'' ACl)llSOALout o= ' SPO(SOAL out o= 5' lnput/ o s#ores obtained in to eamination out o= 1'': e s#ore obtained in sports e*ents out o= 5': e s#ore obtained in tree a#ti*ities out o= 2': planation /o #al#ulate eam per#ent6Addion o= to eam marKs: F Meigtage o= am: B otals#ore based on no o= eam inputs: Sour#e Code 7ln#lude8stdlo.9 7dene ACl)llSMl[TA[ 3' 7de=ine SPO"tSMl[TA[ 2' 7de=ine ]A\SMl[TA[ 5' 7dene ]A\SOAL 2'' 7dene ACl)llSOAL ' 7de=ine SPO"tSOAL 5' lnt main: l lnt eams#orel. a#ti*itiess#orel;sportss#ore< lnt eams#ore2. a#ti*ltiess#ore2.a#tl*itless#ore3I oat eamtotal. a#tl*itlestotal< =loat total per#ent. eamper#ent;sportsper#ent. a#ti*itiesper#ent/ s#an=>?d ?d>; @eams#orel; @eams#ore2:< s#ant>?d>;$.sportss#ore:< s#an=>Bed ?d ?d>;@a#ti*itiess#orel;@a#ti*itiess#ore2;@a#tI*itless#ore3:1 eamtotal 6 eams#orel eams#ore2/ a#ti*itlestotal 6 a#tl*ltiess#orel a#ti*ltiess#ore2 a#ti*itiess#'re3:< eam per#ent 6 tloat:eamtotal ]A\SMl[TA[ I ]A\SOAL< sports per#ent 6 oat:sportss#ore SPO(SMl[TA[ B SPO(SOAL< a#tl*itlesper#ent 6 tloat:a#ti*ltlestotaI Z ACI)IISMl[TA[BACI)IISOAL/ total per#ent 6 eam per#ent sports per#ent a#tl*ltiesper#ent< print=>n(esult>: < print=>notal Per#ent in eamination/?'.2=; eam per#ent:<
print=>notal Per#ent In a#ti*itles/?'.2=V. a#ti*ltiesper#ent:2 print=Vnotal Per#ent In sports/?O.2t>; sports per#ent:< print=>notal Per#entage/?'.2t>; total per#ent:< retum '/ l Sample Input !$$& 34 1&1$1! Sample Output (esult otal Per#ent in eamlnatlon/41.!5 otal Per#ent in a#ti*lties/2!.'' otal Per#ent in sports/13.O otal Per#enlage/$2.35 (esult us; Program > IO 23 > as been su##ess=ully ee#uted
#ourse/ C =rb0e#t Code/ . IO 24 Sel*a \ary =rom S(\ Publi# s#ool is studying 3r grade in s#ool; er mats mam ga*e er a problem to #on*ert te de#imal number in o#tal and eade#imal . Sin#e er mam ga*e so mu# problems to sol*es.Se ent to is broter o is #omputer programmer and reYuested to #reate a program tat #on*erts automati#ally gi*en integer to de#imal; o#tal and eade#imal eYui*alent. Let us elp an programmer to do programX (e=er sample input and output =or =ormatting spe#iW#ation. All oat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdlo.9 int main: lnt de#imal/ s#an=>?d>.@de#imal:< print=>nDe#imal *alue/?dnO#tal *alue/B89onTeade#imal *aQue/B9>. de#imal. de#imal. de#imal:< retum '/ l Sample Input 25 Sample Output De#imal )$Q%&I25 O#tal *alue/31 Teade#imal *alue/1& (esult us; Program > IO 24 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . IO 25 Mrite a program tat prints a =loating point *alue in e itin #olumns ries to print number rigt 0usti=ied to (ounds to ' digit pla#es Prints te number in epone output =or =ormatting spe#i=i#ation. All =loat *alues are rest #orresponds to output.
Sour#e Code 7ln#lude 8stdio.9 int main: l int a6l .integer< oat de#imal/ s#an=>B89d>;@integer:< s#an=>B89=>.@de#imal:< print=>n4 digit integer rigt 0ustiWed to #olumn/?4d>; integer:< print=>n4 digit integer rigt 0ustiWed to 3 #olumn/?3d>; integer:/ BB (ounds to to digit pla#es ponentiai =ormat it te =olloing spe#i=i#ations Prints te number rigt 0usti=ied 3 digits but te number is not rigt ad0usted be#ause tere are only 4 numbers ntial notati'ns#ienti=i# notation: input and Output "ormat/ (e=er sample input and displayed #orre#t to 2 de#imal pla#es. Ali tet in bold #orresponds to input and te print=>n"l'ating point number rounded to ' digits/?.=>.&$!.543:< print=>n"loating point number rounded to 2 digits/?.2t>;de#imal:< print=>n"Ioating point number rounded to 4 digits/?.4=>;de#imal:< BB (ounds to ' digit pla#es printt>n"ioating point number rounded to $ digits/?.$=>;de#imal:< BB Prints te number in eponential notations#ienti=i# notation: print=>n"loating point number in eponential =orm/Boe>.&$!.543: retum '/ : . Sample Input &$! &$!. 543 Sample Output 4 digit integer rigt 0usti=ied to #oiumn/&$! 4 digit Integer rigt 0usti=ied to 3 #oiumn/&$! "loating point number rounded to ' digits/&$$ "loating point number rounded to 2 diglts/&$!.5 "loating point number rounded to 4 digits/&$!.543 "loating point number rounded to $ digits/&$B1542&$$ "loating point number In eponential =orm/&.$!543e'2 (esult us; Program > IO 25 > as been su##ess=ully ee#u ted
#ourse/ C Srb0e#t Code/ . IO 2 Mrite a program to read 1' integers. Display tese numbers by printing tree numbers in a line separated by #ommas Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdlo.9 int maln: rm a;b#;d;e;t.g;;i.^< s#an=>?d ?d ?d ?d Bod ?d ?d ?d ?d B9d>; @a;@b;@#;@d;@e.@=;@g.@;@l;@i:< print=>n?d.?d;?dn?d.?d.B89dn?d;B89d.?dn?d>; a;b.#.d;e;=.g.;i.0:/ retum O/ l Sample Input
1 2 3 4 s s ! a & 1' Sample Output 1;2;3 4;5; !.a;s 1' (esult us; Program > IO 2 > as been su##ess=ully ee#uted
Course/ C 11 . IO 2$ Sub0e#t Code Mrite a program to prQnt te #ount o= e*en numbers beteen 1 and 2'' and pnnt teir sum Input and Output "ormat (e=er sample Qnput and output =or =ormatting spe#r=r#atron All =loat *alues are displayed #orre#t to 2 de#rmal pla#es All tet In bold #orresponds to mput and te rest #orresponds to output Sour#e Code 7in#lude8stdlo.9 rm maln: l lnt a6'.i< =ori6'?d>;a:< retum O/ l Sample Input ' Sample Output ' (esult us; Program > IO 2$ > as been su##ess=ully ee#uted
Course/ C 11 Sub0e#t Code/ . IO 2& Mrite a program spe#iW#ation. All output. Sour#e Code 7ln#lude8stdlo.9 int maln: l #ar #_1'^< int l;#ount6'< s#anl>?s>;#:< =ori6O<#_i^l6'
print=>n)oeQs6B od retum '/ l Sample Input srmunl*ersity Sample Output )oels64 (esult us; Program > to #ount numbers o= *oels in a tet Input and Output "ormat/ (e=er sample input and output =or =ormatting =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to eZ QQ #_l^66l ;COl.lt^G IO 2& > as been su##ess=ully ee#uted
#ourse/ C Wib0e#t Code/ . I'3 Mrite a program to #al#ulate te perimeter o= a tnangle using Teros =ormula Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 7ln#lude8mat.9 Int main: =loat a;b;#< =loat s;area< s#an=?=?=?=> .@a. @b@#:< s 6 ab#:B2< area 6 sYrts_s+a:>s+b:Zs+#::< print=>perlmeter o= triangle ls/?=>.area:< return '/ l Sample Input 2 3 4 Sample Output perimeter o= triangle is/2.&'4!3! (esult us; Program > IO 3 > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . IO 3' Mrite a program to read te address o= a user .Display te result by breaKing it into multiple lines Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 BB7ln#Qude8#onio.9 Int maln:
l lnt no< long Int pin/ #ar area_2'^< SC$W=>BoCQ. @n':2 s#an=>?s>; area:< s#an=>Bold>; @pln:/ print=>Address>:< print=>nTouse -umber/?d>; n':I print=>nArea/?s>. area:/ print=>nPln Code/?Qd>; pin:< retum '< l Sample Input 34$& S(\Cennai '32'3 Sample Output Addl&SS Touse -umber/34$& Area/S(\Cennal Pin Code/'32'3 (esult us; Program > IO 3' > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . IO 31 Prana* intelligent in playing riddle it numbers so; e ga*e is sister a pule to sol*e in i# se need to sol*e by adding te le=t side integral part o= to de#imal numbers. planation/ (a0u ga*e is sister to de#imal numbers / 23.44 and 33.22 ; Tis sister need to identi=y te le=t side integral part o= gi*en numbers are 23 and 33 . "inally te added output *alue is 5. Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7Qn#lude8stdlo.9 lnt main: l =loat ab< lnt sum/ s#an=>?=>; @a:< s#an=>?=>; @b:/ sum 6 int: ab< print=>nsum/?d>.sum:< retum '< l Sample Input 12.22 11.22 Sample Output sum/23 (esult us; Program > IO 31 > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . I' 32 \ana* ad a play it is =riend goura*; e ga*e a number tat to read a =loating point number and asKed im to display te rigt most digit integral part o= te number. Please elp goura* to display te rigt most integral part o= te number. planation / I= te input is gi*en 124.34; ten te output to be displayed is 4 i.e: Ue=ore de#imal te integral part is 124 ; in tat last digit is 4. Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7In#lude8stdlo.9 lnt main: l =loat a< lnt num; digit< s#an=>?t>; Sta:< num 6 lnt:a< digit 6 num?1'< print=>(igtmost integer digit o= ?t6?d;a;digit:< retum '< l Sample Input 233.444 Sample Output "tigtmost lnteger digit o= 233.444'''63 (esult us; Program > IO 32 > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . IO 33 (a0 deposit H1'''' into a banK a##ount paying !? simple interest per year. Te le=t te money in =or 5 years. "ind te interest earned and te amount at te end o= tose 5 years by (a0X Telp im to =ind te interest and amount resided in banK a=ter 5 yearsX SP 1/ "ind an interest by using te =ormula l6P86i86t; ere I is interest; P is total prin#ipal; i is rate o= interest per year; and t is total time in years. SP 2/ "ind an amount by using te =ormula A6Pl. Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 7ln#lude8mat.9 int maln: l oat p. r; t. interestamount< s#an=>?=?=?=>;@p;@r.@t:< lnterest6prFt:B1''< amount6lnterestp< print=>nlnterest6?'.2=>interest:2 print=>nAmount6?'.2=>;amount:< retum '< l
Sample Input 1'''' ! 5 Sample Output Qnterest635''.'' Amount6135''.'' (esult us; Program > IO 33 > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . IO 34 Telp (a0a to #al#ulate a =irst salary tat e got =rom te organiation ; e as #on=used it an salary #redited in s a##ount . Te asKed is =riend ritu to identi=y o salary pay got #al#ulated by gi*ing te =ormat o= salary . Tis basi# pay to be entered by user: and (itu de*eloped a so=tare to #al#ulate te salary pay;it =ormat gi*en as belo T"lA6$'? o= te basi# pay; dA64'? o= basi# pay . bonus 6 25 ? o= ra input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output Sour#e Code 7in#iude8stdio.9 7detine T(A '.$' 7de=ine A '.4' int maln: i oat basi#. sal< s#an=>B89=>.@basi#:< sai 6 basi# T(A basi#: A Z basi#:< print=>otai Saiary6?=;sai:/ retum O/ l Sample Input 5'''' Sample Output otal Salary61 1oooo.oooooo (esult us; Program > IO 34> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . IO 35 Mrite a program to display a gro#ery bill o= te produ#t pur#ased in te small marKet by ,on by getting =olloing input =rom te user [et te produ#t name [et te pri#e o= te pr'du#tPri#e per %nit: [et te Yuantity o= te produ#t pur#ased lnput and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7Qn#lude8stdlo.9 int maQn: #ar prodname_1'^/ Int Yty<
=loat prod pri#e;tot prl#e/ s#an=>?s>;prodname:< s#an=>Bt9=>;@prodpri#e:< s#an=>?d>.@Yty:< tot prI#e6Ytyprod pri#el print=>nProdu#t Details>:< print=>n?s>;prodname:I print=>n?=;prodpri#e:< print=>nB89d>.Yty:< print=>nUQQl/?'.2=>;totprl#e:< retum '< l Sample Input soap 33.'' 2 Sample Output Produ#t Details soap 33.'''''' 2 Uill 2.'' (esult us; Program > IO 35 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ .lO4 [i*en to #ities at geograpi# #oordinates A;yA: and U;yU:; and #al#ulate te distan#e beteen =rom #ity A to #ity UX -ote/ %se te distan#e beteen points =ormula Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdio.9 7ln#lude8mat.9 lnt maln: t lnt 1. y1; 2; y2/ oat dist< s#an=>?d?d>.@1 .@y1 :< s#an=>?d?d>;@2;@y2:< dist6sYrtpo2+1:;2:poy2+y1:;2::< print=>ne distan#e beteen to points ls/?'.2= units>;dist:< retum O< l Sample Input 1233 134 Sample Output e distan#e beteen to points is/2&.'2 unlts (esult us; Program > IO 4 > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/
. I'5 Mrite a program to s#an te gi*en input and per=orm unary pre=i in#rement and de#rement operators. Condition / )ariable name to be used/ Preadd; Presub; Posadd; Possub Sour#e Code 7in#lude8stdlo.9 int maQn: l int num;posadd;possub;preadd;presub< s#an=>Bod.@num:l posadd6num< possub6num++< preadd6num< presub6++num< print=>ne )alue o= num6?d>.num:< print=>ne )alue o= num6B9d>; posadd:< print=>ne ne )alue o= num6?d>preadd:/ print=>ne )alue o= num6?d>;preadd:< print=>ne )alue o= numE+6B9d>.possub:< print=>ne ne )alue o= num6Bodipresub:< retum O/ l Sample Input 2 Sample Output e )alue o= num62 e )alue o= num62 e ne )alue o= num63 e )alue o= num63 e )alue o= num++63 e ne )alue o= num62 (esult us; Program > IO 5 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . I'$ Mrite a program to =ind te largest o= tree numbers using ternary operator Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#iW#ation. All oat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7 in#lude 8stdio.9 rm main: i int a; b; #. big< s#an=>B89d ?d ?d>; @a; @b; @#: 1 big6a9b:Xa9#:Xa/#:/b9#: Xb/#:/ print=Vne biggest number ls/?dV; big: < return '< l Sample Input 4 5 Sample Output e biggest number ls/ (esult us; Program > IO $ > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . I'& Let us elp (a0e to per=orm basi# bitise operation by pro*iding tree inputs gi*en to te program it te =olloing #onditions are met; Uitise And Uitise O( Uit Mise -ot #omplement o= Positi*e number #omplement o= negati*e number (igt si=t by ' o= gi*en number (igt si=t by 1 o= gi*en number Le=t si=t by ' o= gi*en number Le=t si=t by 1 o= gi*en number Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7In#Iude 8stdio.9 int main: int a; b;#< s#an=>?dB89d?d>;@a.@b;@#:/ print=>Uitise And o= B89d and ?d6?dn>; a.b.a@b:/ print=>Uitlse O( o= ?d and ?d6?dnV.a.b; alb:< print=>Uit Mise -ot o= ?d and ?d6?dn>; a;b;ab:< print=>#omplement o= Bod6Bodl>;$;+3:c print=>#ompIement o= +?d6?dn.b.E+b:< print=>(lgt si=t by ' o= ?d6?dn>.#;#99':< print=>(Qgt si=t by 1 o= B89d6?dn>.#.#991:< print=>Le=t si=t by ' o= ?d6?dn>;#;#88':< print=>Le=t si=t by 1 i= ?d6Bodn>.#;#881:< retum '/ l Sample Input 23 4 4 Sample Output Uitise And o= 23 and 464 Uitise O( o= 23 and 4623 Uit Mise -ot o= 23 and 461& #omplement o= 236+24 #omplement o= +463 (igt si=t by ' o= 464 (igt si=t by 1 o= 462 Le=t si=t by ' o= 464 Le=t si=t by 1 i= 46$ (esult us; Program > IO & > as been su##ess=ully ee#uted
#ourse/ C Sub0e#t Code/ . Tello Mel#ome to S(\ %ni*ersity On Syams "irst #lass o= ype+riting te tea#er told im to rite te ord Tello Mel#ome to S(\ %ni*ersityJ Please elp im to print ello orld te gi*e tet Sour#e Code 7in#lude 8stdio.9 lnt maln: l print=>TeQQo Mel#ome to S(\ %ni*ersity>:< return '<
l Sample Input ' Sample Output Tello Mel#ome to S(\ %ni*ersity (esult us; Program > Tello Mel#ome to S(\ %ni*ersity> as been su##ess=ully ee#uted
#ourse/ C X/.Qb0e#t Code/ . Addition o= numberslnteger data type: ,ennys ome orK =or =irst day is to =ind addition o= to numbers; elp 0enny to sol*e te problem Sour#e Code 7in#lude8stdio.9 Int main: l int a; b; #< s#an=>?dB89d>; @a; @b:< C 6 T+bl print=>e addition o= to number is/B89d>;#:< return '< : Sample Input 2 Sample Output e addition o= to number is/$ (esult us; Program >Addition o= numberslnteger data type:> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . D+/Di*ision o= numbers Tarinis ome orK =or =ourt day is to di*ide to numbers; elp Tarini to sol*e te problem Sour#e Code 7in#lude8stdio.9 lnt main: int a. b; #< s#an=>?d ?dV.@a.@b:/ # 6 aBb< prlnt=>e Di*ision o= to number is/?d>;#:< return '< l Sample Input ! 2 Sample Output e Di*ision o= to number is/3 (esult us; Program > D+/Di*ision o= numbers> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/
. "loat Di*ision o= numbers Tarinis ome orK =or =ourt day is to di*ide to numbers; elp Tarini to sol*e te problem Sour#e Code 7in#lude8stdio.9 int main: l oat a;b;#< SC$ll=>Bo= ?=.@a;@b:/ # 6 aBb< prlnt=>e Di*ision o= to number is/?=>#:< return '< l Sample Input !.2 3.4 Sample Output e Di*ision o= to number is/2.11!4! (esult us; Program > "loat Di*ision o= numbers> as been su##ess=ully ee#uted
#ourse/ C =rb0e#t Code/ . \odule o= numbers Tarinis ome orK =or =ilt day is to =ind reminder o= to numbers; elp Tarini to sol*e te problem Sour#e Code 7in#Iude8stdio.9 int main: l int a. b; #< s#an=>?d?d>; @a;@b:< #6a?b< print=>e modulo o= to number is/?d>;#:< return '< : Sample Input 2 Sample Output e modulo o= to number ls/' (esult us; Program > \odule o= numbers> as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C T . \ultipli#ation o= numbers Tarinis ome orK =or tird day is to multipli#ation oi to numbers; elp Tarini to sol*e te problem Sour#e Code 7in#lude8stdio.9 int main: i =loat d.e;i< s#an=>?iBo=>;@d;@e:< =6de< print=>ne \ultipli#ation o= to number is/?=>;=:<
print1>ne \ultipli#ation oi to number is/?.2=>;=:< return '< l Sample Input !.2 1.5 Sample Output e \ultipli#ation o= to number is/1'.!&&&&& e \ultipli#ation o= to number is/1'.$' (esult us; Program > \ultipli#ation o= numbers > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Addition o= to numbers Tarinis ome orK =or te se#ond day is to subtra#t to numbers; elp Tarini to sol*e te problem Sour#e Code 7in#lude8stdlo9 lnt main: l int a. b; #< =loat d.e;l< BBprint=>nter to numbers to addn>:< s#an=>?dB89d>;@a;@b:< s#an=>?=?=>.@d.@e:I C 6 ab/ =6de< print=>e Addition o= to number ls/?dn;#:< print=>e Addition o= to number is/?.2t;t:< return O< l Sample Input 4 4 5.5 .4 Sample Output e Addition o= to number ls/$ e Addition o= to number ls/11.&' (esult us; Program >Addition o= to numbers > as been su##ess=ully ee#uted
#ourse/ C =ub0e#t Code/ . \odulo o= numberslnteger data type: ,ennys ome orK =or "i=t day is to Wnd modulo o= to numbers; elp 0enny to sol*e te problem Sour#e Code 7in#lude8stdio.9 Int main: l int a; b; #< s#an=>?dB86d>.@a;@b:< # 6 aBobi print=>e reminder o= to number is/?d>.#:< return '<
: Sample Input 2 Sample Output e reminder o= to number is/' (esult us; Program > \odulo o= numbersInteger data type:> as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C T m . Display your na Mrite a program to g Sour#e Code 7in#Iude 8stdio.9 mt main: N #ar a_2'^< s#an=>?s>;a:< print=>our name Qs/?s return '< l Sample Input S(\%ni*ersity Sample Output our name is/S(\%ni*e (esult us; Program >Dis e eta string and print it. 63:< rsity play your name> as been su##ess=ully ee#uted
Course/ C 11 Sub0e#t Code/ . D+1'/ "loa Mrite a C prog Sour#e Code 7in#lude8stdio.9 int main: N int a.b< =loat .y< s#an=>?=>;@:I s#an=>?=>;@y:< a 6 int:O.5:< b 6 int:y'.5:2 print=>)alue ls/?d>;a:/ .. .?d..Zb print= n)alue ls. retum '< l
Sample Input 4. 5.$ Sample Outpu )alue is/5 )alue is/ (esult us; Program t to Integer t ram to #on*ert integer to =loat number. :< > D+1'/ "loat to Integer> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . D+11/Celsius o "areneit \er#y and er =riends ent a trip to ill station during inter. It is raining ea*ily so tey #ant go outside. mer#y =elt *ery bored and de#ided to asK pule to er =riends. Se ga*e tem te temperature in Celsius =ormat and asKed tem to #on*ert it to "areneit. Sour#e Code 7in#lude 8stdio.9 oat temp=< BZ degrees tareneit B oat temp#< BZ degrees #entigrade B #ar linetet_5'^/ B a llne o= input ZB int main: N =getslinetet; sieo=linetet:. stdin:< ss#an=llnetet; Bo=>; @temp#:/ temp= 6 &.' B 5.': temp#: 32.'< print=>Bo= degrees "areneit>; temp=:< return':/ l Sample Input 45.' Sample Output 1 13.'''''' degrees "areneit (esult us; Program > D+11/CeIsius o "areneit > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . D12/ Print dateBmontBear Mrite a C program to print your name; date o= birt. and mobile number. Sour#e Code 7in#lude 8stdio.9 lnt maIn: t #ar a_2'^; b_2'^I int date;year.#ode.number/ s#an=?s>;a:< s#an=>B9s>.b:/ s#an=>?d>;@date:< s#an=V?d>;@year:< s#an=>?d>;@#ode:/ s#an=>?d;@number:< print=>-ame/?s>;a:<
print=>nDOU/B89s ?d ?d>;b;dateyear:< print=>n\obile/?d+?d>;#ode.number:< return '< l Sample Input S(\%ni*erslty \ar# 23 1 &&1 && 1 2345!$&' Sample Output -ame/S(\%ni*ersity DOU/\ar# 23 1&&1 \obiQe/&&+12345!$&' (esult us; Program > D12/ Print dateBmontBear> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . D14/ Print Details ,on 0oined in is ne #ollege in #ennai. e College is rated as one o= te best pri*ate uni*ersity in India. On =irst day o= is #ollege; ,on tea#er a*e asKed is personal details =or data purposes. indly elp 0on to per=orm te tasK using #oding. (e=er same input and output =or details Sour#e Code 7ln#lude 8stdio.9 int maln: l #ar name_2O^/ int age;yearI =loat per#entage< s#an=>?s>; name:< s#an=>?d>;@age:/ s#an=>?=>;@per#entage:/ s#an=?d>;@year:< print=>-ame/?s>;name:I print=>nAge/?d>;age:< print=>nPer#entage 1B89=;per#entage:< print=>near o= Passlng/?d>year:< return '< l Sample Input 0on 21 !&.& 2'1! Sample Output -ame0on Age/21 Per#entage/!&.&''''2 ear o= Passlng/2'1! (esult us; Program > D14/ Print Details> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Con*ersion on spe#i=i# Mrite a C program to #on*ert spe#i=ied days into years; eeKs and days. Sour#e Code 7in#lude 8stdio.9 rm maQn: N Int days; years; eeKs/ s#an=>?d>;@days:/ BB Con*erts days to years. eeKs and days years 6 daysB35< eeKs 6 days ? 35:B!< days 6 days+ years35: eeKs!::< print=>ears/?dn>; years:< print=>MeeKs/?dn>; eeKs:< print=>Days/?d>; days:< return '/ l Sample Input 345 Sample Output ears/& MeeKs/24 Days/3 (esult us; Program >Con*ersion on spe#i=i# > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Age Cal#ulator De#lare me as an integer. [et to integer *alues as mentioned in sample input and output De#lare a*erage as a =loat and assign it te a*erage o= me and you. en using one print= =or ea# line; print te =olloing. e numbers are printed using te *alues o= te *ariables. e last line starts on a tab position Sour#e Code 7ln#lude 8stdio.9 lnt maln: l int a;b< =loat #/ s#an=>?d B89d>;$+a@b:< #6ab:B2/ print=>l am/?dnou are/B89dnMe are around/?=a.b;#:< return '< l Sample Input 4' 2' Sample Output I am/4' ou are/2' Me are around/3'.'''''' (esult us; Program > Age Cal#ulator > as been su##ess=ully ee#uted
#ourse/ C X/.Qb0e#t Code/ . Cube o= a -umber Mrite a C program to =ind te #ube o= a number Sour#e Code 7in#lude 8stdio.9 int main: N Int a< s#an=>?dV;@a:< print=>?d.aZaa:I return '< l Sample Input 2 Sample Output 3 (esult us; Program >Cube o= a -umber> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . SYuare o= a -umber Mrite a C program to =ind te sYuare o= a number Sour#e Code 7in#lude 8stdio.9 int main: N Int a< s#an=>?dV;@a:< print=>?d.aZa:< return '< l Sample Input 2 Sample Output 4 (esult us; Program >SYuare o= a -umber> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Subtra#tion o= numberslnteger data type: ,ennys ome orK =or Se#ond day is to =ind subtra#tion o= to numbers; elp 0enny to sol*e te problem Sour#e Code 7in#lude8stdio.9 int main: int d;e.=< s#an=>?d ?d>;@d.@e:< =6d+e/ print=>ne Subtra#tion o= to number ls/B89d>t:/ return '< l Sample Input 2
Sample Output e Subtra#tion o= to number Is/4 (esult us; Program >Subtra#tion o= numbersQnteger data type: > as been su##ess=ully ee#uted
#ourse/ C Wib0e#t Code/ . \ultipli#ation o= numberslnteger data type: ,ennys ome orK =or ird day is to =ind \ultipli#ation o= to numbers; elp 0enny to sol*e te problem Sour#e Code 7in#lude8stdio.9 int main: l int d.e.=< s#an=>?d?d>;@d;@e:< =6d>e< print=>ne \ultipli#ation o= to number is/?d>;=:< return '< l Sample Input 2 Sample Output e \ultipli#ation o= to number is/12 (esult us; Program > \ultipli#ation o= numberslnteger data type: > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Di*ision o= numberslnteger data type: ,ennys ome orK =or "ourt day is to =ind Di*ision o= to numbers; elp 0enny to sol*e te problem Sour#e Code 7in#lude8stdio.9 Int main: int a. b; #< s#an=>?dB89d>; @a; @b:< #6aBb< prInt=>e di*ision o= to number ls/?d>;#:< return '< l Sample Input 2 Sample Output e di*ision o= to number is/3 (esult us; Program >Di*ision o= numberslnteger data type:> as been su##ess=ully ee#uted
#ourse/ C Stib0e#t Code/
. Substra#tion o= numbers Tarinis ome orK =or se#ond day is to subtra#t to numbers; elp Tarini to sol*e te problem Sour#e Code 7in#lude8stdio.9 int main: t oat d.e;=< s#an=>?= ?=V;@d.@e:I =6d+e< print=>ne Subtra#tion o= to number Is/?=>;t:< print=>ne Subtra#tion o= to number is/B89.2tn>.t:< return '< : Sample Input !.2 1.5 Sample Output e Subtra#tion o= to number ls/5.!''''O e Subtra#tion o= to number is/5.!' (esult us; Program > Substra#tion o= numbers > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Ali#e in Monderland Ali#e as bored tat day;so se as sitting on te ri*erbanK .SuddenQy se noti#es a talKing; Mite (abbit it a po#Ket at# .lt ran =ast;and se =olloed it; don a rabbit ole .Se =ell into te ole and =ound a magi#al onderland it darK trees; beauti=ul =loers.Se =ound many ays numbered =rom 1;2;3; ...... ..1$.se as #on=used i# is te rigt ay tat ill lead er to er ome. Se =ound a #ute bird; standing in one o= te tree. Ali#e asKed te bird te ay to go ba#K to er ome.e bird said a to digit number say 23 : and asKed er to =ind te sum o= its digits 2365: and tat numbered ay ill lead er to er ome.Ali#e as already #on=used; so pls elp Ali#e in =inding te route to er ome.... lnput "ormat/ Input #onsists o= an integer #orresponding to te 2+digit number. Output "ormat/ Output #onsists o= an integer #orresponding to te sum o= its digits. (e=er sample input and output =or =ormatting spe#i=i#ations Sour#e Code 7ln#lude8stdio.9 Int maln: l lnt a;b.#.d< s#an=>?d>.@a:1 b6aB1'< #6aB'1'< d6bC/ i=a9&&: print=>nnot a 2 digit numbern>:< else print=>nAQi#e must go in pat+?d>.d:< retum '/ l Sample Input 23 Sample Output
Ali#e must go in pat+5 (esult us; Program > Ali#e in Monderland > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . A*erage S#ale A gro#er as a s#ale o= (s. S1;(s . S2; (s. S3 ;(s. S4 and (s. S5 =or 5 #onse#uti*e monts. To mu# sale must e a*e in te sit mont so tat e gets an a*erage sale =or (s.]X Mrite a C program to #ompute te sale in te t "ormat/ Input =ormat/ Input #onsists o= 5 integers and 1 oat. e =i*e integers #orresponds to s1 ;s2;s3;s4;s5. e =loat input #orresponds to . Sour#e Code 7in#lude8stdio.9 int maln: =loat a;b.#< s#an=>B89=>;@a:< HC$=>Bo=>; @b:< #6a+ba:B1'':< print=>e selllng pri#e o= te #y#le ls (s6?.2=n>;#:< retum '/ l Sample Input 14'' 15 Sample Output e selling pri#e o= te #y#le is (s61 1&'.'' (esult us; Program > A*erage S#ale > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . A)(A[ SAL A gro#er as a sale o= (s. s1; (s. s2; (s. s3; (s. s4 and (s. s5 =or 5 #onse#uti*e monts. To mu# sale must e a*e in te sit mont so tat e gets an a*erage sale o= (s. X Mrite a C program to #ompute te sale in te t mont. lnput "ormat/ Input #onsists o= 5 integers and 1 =loat. e W*e integers #orrespond to s1; s2; s3; s4 and s5. e =loat input #orresponds to . Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ations. e =loat *alues are displayed #orre#t to 2 de#imal pla#es Sour#e Code 7ln#lude 8stdio.9 int maln: l Int s.a;b;#;d;e< =loat ;=< s#an=>?d;@a:< s#an=B9d>;@b:< s#an=>?#l>;@#:< s#an=>?d>;@d:< s#an=>Bed>.@e:< s#an=>?=>;@:/ s6ab#de:< =6:+s< print=>e reYuired sale in te sit mont is ?.2=>; =:< retum O<
l Sample Input 4/+as &2! sass !23' 52 !'''.' Sample Output e reYuired sale in te sit mont ls !&&1.'' (esult us; Program > A)(A[ SAL> as been su##ess=ully ee#uted
#ourse/ C Silb0e#t Code/ . Cal#ulating SP A man buys a #y#le =or (s. a and sells it at a loss o= b?. Mat is te selling pri#e o= te #y#leX Mrite a C program to #ompute te selling pri#e. input "ormat/ e =irst input is an integer i# #orresponds to a. e se#ond input is an integer i# #orresponds to b. Sour#e Code 7in#lude8stdlo.9 lnt maln: oat a.b.#< s#an=>B#=>;@a:< s#an=%?=L@by #6afba:B1'':< print=Ve selling pri#e o= te #y#le is (s6?.2=>.#:< retum O/ : Sample Input 14'' 15 Sample Output e selling pri#e o= te #y#le ls "ts61 1&'.'' (esult us; Program > Cal#ulating SP> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Cal#ulating [ain Per#entage )iKram buys an old s#ooter =or (s. A and spends (s. U on its repairs. I= e sells te s#ooter =or (s. C ; at is is gain ?X Mrite a C program to #ompute te gain ?. Input "ormat/ e =irst input is an integer i# #orresponds to A. e se#ond input is an integer i# #orresponds to U. e tird input is a oat i# #orresponds to selling pri#e Sour#e Code 7ln#lude8stdlo.9 lnt main: =loat a.b;#.d;e< s#ant>?=>;@a:< s#an=>Bo=>; @b:< s#ant>?t>;@#:< d6$bI e6#+d:rd:1''< printt>e gain per#entage is6?.2t>.e:/ retum '/ : Sample Input 4!'' aoo 5$''
Sample Output e gain per#entage is65.45 (esult us; Program > Cal#ulating [ain Per#entage> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Cal#ulating Per#entage S(\ %ni*ersity buys an old s#ooter =or (s. A and Spends (s. U on its repairs. i= e sells te s#ooter =or (s.C ; at is is gain ?X Mrite C program to #ompute te gain ?X Input =ormat/ e =irst input is an integer i# #orresponds to A . e se#ond input is an integer i# #orresponds to U. e tird input is a =loat i# #orresponds to gain ? Sour#e Code 7in#lude8stdio.9 int main: =loat a;b;#;d;e/ s#an=>B89=>;@a:< s#an=>?=>; @b:< s#an=>?=>;@#:/ d6a+Pb/ e6#Ed:Bd:1''< print=>e gain per#entage is6?.2=>.e:< retum O/ : Sample Input 4!'' aoo saoo Sample Output e gain per#entage is65.45 (esult us; Program > Cal#ulating Per#entage> as been su##ess=ully ee#uted
#ourse/ C Sub0e#t Code/ . Cal#ulating SP A man buys a #y#le =or (s. A and sells its a loss o= U? . Mat is te selling pri#e o= te #y#leX Mrite a C program to #ompute te selling pri#e Input =ormat/ e =irst input is an integer i# #orresponds to A . e se#ond input is an integer i# #orresponds to U. Sour#e Code 7in#lude8stdlo.9 lnt maln: oat a;b.#< s#an=>B#=>;@a:< s#an=>B#=>; @b:< #6a+ba:B1'':< print=>e selling pri#e o= te #y#le ls "ls6B#.2=;#:< retum '< : Sample Input 14'' 15 Sample Output e selling pri#e o= te #y#le ls (s61 1&'.'' (esult us; Program > Cal#ulating SP> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Computing ] e #ost prin#e o= n arti#les is te same as te selling pri#e o= ] arti#les . I= te pro=it is p? ten at is te *alue o= X lnput =ormat/ e =irst input is an integer i# #orresponds to n te se#ond is an integer i# #orresponds to p Output "ormt/ (e=er sample Input and output =or =ormatting Spe#i=i#ations e =loat *alues are displayed #orre#t to 2 de#imal pla#es. Sour#e Code 7ln#Iude8stdlo.9 int maln: =loat a.b;< oat #;d< s#an=>Bo=>; @a:< s#an=>?t>;@b:< #6b'.'1:< d6C1 I ]6a.>d< print=>e *alue o= ] ls6?.2=>.:/ retum '< l Sample Input 12.5 14.5 Sample Output e *alue o= ls61'.&2 (esult us; Program > Computing ] > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . "-CI-[ T [(O%-D e #ollege ground is re#tangular in sape. e \anagement de#ides to build a =en#e around te ground. ln order to elp te #onstru#tion orKers to build a straigt =en#e; tey planned to pla#e a ti#K rope around te ground. ey anted to buy only te ea#t lengt o= te rope tat is needed. ey also anted to #o*er te entire ground it a ti#K #arpet during rainy season. ey anted to buy only te ea#t Yuantity o= #arpet tat is needed. ey reYuested your elp. Can you please elp tem by riting a C program to tind te ea#t lengt o= te rope and te ea#t Yuantity o= #arper tat is reYuiredX Input "ormat/ Input #onsists o= 2 integers. e =irst integer #orresponds to te lengt o= te ground and te se#ond integer #orresponds to te breadt o= te ground. Sour#e Code 7Qn#lude8stdio.9 Int main: int Lengt;Midt;Qen;Yuan< s#an=>B89d>.@Lengt:< s#ant>?d.@MQdt:< len62ZLengtMidt:< Yuan6LengtMldt< printi>(eYuired lengt is ?#lm>.len:< print=>n(eYuired Yuantity o= #arpet is ?dsYm>.Yuan:/ retum '/
l Sample Input so 2' Sample Output (eYuired lengt is 14'm (eYuired Yuantity o= #arpet is 1'''sYm (esult us; Program > "-CI-[ T [(O%-D> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . "inding bitise A-D o= to numbers Mrite a program to =ind te bitise A-D o= to de#imal numbers. An A-D gate reads 2 input eiter ' or 1 and outputs 1 iW bot te inputs are 1. Similarly rite a program to read to de#imal numbers and =inds A-D o= to numbers . ]A\PL / 3:1' 6 '11:2 5:1' 6 1'1:2 A-D o= 3 and 4 is / 1:1' 6 ''1:2 Sour#e Code 7in#lude8stdio.9 lnt main: l lnt a;b.#< s#an=?d>;@a:/ s#an=>?d.@b:1 #6a@b/ print=>Uitise A-D o= Bod and ?d is/?d>.ab;#:< retum '/ l Sample Input 12 23 Sample Output Uitise A-D o= 12 and 23 is/4 (esult us; Program > "inding bitise A-D o= to numbers> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . "inding bitise ]O( o= to numbers Mrite a program to =ind te bitise ]O( o= to de#imal numbers. An ]O( gate reads 2 input eiter ' or 1 and outputs ' i= bot te inputs are same and outputs 1 i= bot te inputs are di==erent. Similarly rite a program to read to de#imal numbers and =inds ]O( o= to numbers. ]A\PL 1 3: 1' 6 '11: 2 5: 1' 6 1'1: 2 ]O( o= 3 and 4 is / : 1' 6 11': 2 Sour#e Code 7in#lude8stdio.9 lnt main: l lnt a;b.#< s#an=>?d>.@a:< s#an=>?d>.@b:l #6a>b< print=>Uitise ]+O( o= ?d and ?d is6B89d>.a;b.#:/ retum '/ l Sample Input 12
23 Sample Output Uitise ]+O( o= 12 and 23 is62! (esult us; Program > "inding bitise ]O( o= to numbers> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . "inding O( o= to numbers Mrite a program to =ind te bitise O( o= to de#imal numbers. An O( gate reads 2 input eiter ' or 1 and outputs ' i== bot te inputs are ' else 1. Similarly rite a program to read to de#imal numbers and =inds O( o= to numbers . ]A\PL / 3: 1' 6 '11: 2 5: 1' 6 1'1: 2 O( '13 and 4 is / !: 1' 6 111: 2 Sour#e Code 7in#lude8stdio.9 lnt main: l int a;b.#< s#an=>?d>.@a:< s#an=>B89d>.@b:/ #6alb< print=>Ultlse O( o= ?d and ?d is/?d>;a;b.#:< retum O/ l Sample Input 12 23 Sample Output Uitise O( o= 12 and 23 is/31 (esult us; Program > "inding O( o= to numbers > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . "inding O( o= to numbers Mrite a program to =ind te bitise O( o= to de#imal numbers. An O( gate reads 2 input eiter ' or 1 and outputs ' i== bot te inputs are ' else 1. Similarly rite a program to read to de#imal numbers and =inds O( o= to numbers . ]A\PL / 3: 1' 6 '11: 2 5: 1' 6 1'1: 2 O( '13 and 4 is / !: 1' 6 111: 2 Sour#e Code 7in#lude8stdio.9 lnt main: l lnt a;b.#< s#ant>?d>.@a:< s#an=>?d>.@b:l C6alb/ print=>Uitise O( o= ?d and ?d is6?d>.a.b.#:/ retum '/ l Sample Input 12 23 Sample Output Uitise on o= 12 and 23 is631 (esult
us; Program > "inding O( o= to numbers > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . "ind \ode Mrite a program to =ind te mode o= a gi*en list o= integers. \ode o= a number is de=ined as te number i# is most =reYuently o##urred. "or eample. L 6 N1;2;2;3c BB Tere mode is 2most =reYuently o##urred: lt is possible tat multiple ansers are possible =or a list. In tat #ase pnnt all possible ansers in non+in#reasing order lnput "irst Line o= input #ontains an lnte er t re resent t . . g p ing e number o= test #ases; Mere =irst line o= ea# test #ase as an integers - + number o= integers in list; -et line #ontains - integers. Output/ print all te possible modes in non+in#reasing order. Constraints/ 186t861'' 186-81''''' 186a_i^861'''''' Sour#e Code 7ln#lude8stdlo.9 7de=lne maa. b: a: 96 b:: X a: / b:: lnt maln: int t; n; no; i< s#an=>?d>; @t:< llet++ @@ s#an=>?d>; @n::N int _1'''''1^ 6 NOc; m1 6 1. m2 6 '< ilen++ @@ s#an=>?d>; @no:: _no^; m1 6 mam1 no:< =ori 6 1< I 86 m1/ l: m2 6 mam2; _l^:< =ori 6 m1< i 96 1< i++: i=_l^ 66 m2: print=>?d I:< print=>n:< l return '< l Sample Input 2512222122334 Sample Output 2 32 (esult us; Program >"ind \ode > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . "ind (emainder Mrite a program to =ind te remainder en to gi*en numbers are di*ided. Input e =irst line #ontains an integer ; total number o= test #ases. en =ollo lines; ea# line #ontains to Integers A and U. Output "ind remainder en A is di*ided by U. Constraints 1 X ZX 1'''1 XA;U X 1'''' Sour#e Code 7in#lude8stdio.9 maln: l int t/ s#an=>?d>.@t:< ilet++: l int a;b.#< s#an=>?d BodV; @a;@b:< #6a?b2
printt>(emainder is ?dn>;#:< l l Sample Input 3 1 2 1'' 2'' 1' 4' Sample Output (emainder is 1 (emainder ls 1'' (emainder is 1' (esult us; Program >"ind (emainder > as been su##ess=ully ee#uted
#ourse/ C S0ib0e#t Code/ . "O%( SASO-(S Dines also 0oined te group o= 3 idiots and no teir group is #alled "our Seasoners. \eanile; Uinoy as mo*ed to a ne ouse in te same lo#ality. -o te ouses o= A0ay; Uinoy and Candru are in te lo#ated in te sape o= a triangle. Dines also as mo*ed to a ouse in te same lo#ality. Men A0ay asKed Dines about te lo#ation o= is ouse ; Dines said tat is ouse is eYuidistant =rom te ouses o= te oter 3. oug A0ay as good in \atemati#s; e as puled. Can you please elp A0ay outX [i*en te 3 *erti#es N1;y1:; 2;y2: and 3;y3:c o= a triangle; rite a C program to determine te point i# is eYuidistant =rom all te 3 *erti#es. Input "ormat/ Input #onsists o= integers. e =irst integer #orresponds to 1 . e se#ond integer #orresponds to y1. e tird and =ourt integers #orrespond to 2 and y2 respe#ti*ely. e =i=t and sit integers #orrespond to 3 and y3 respe#ti*ely. Sour#e Code 7ln#lude8stdlo.9 lnt maln: l int ]1 ;]2.]3;1 .2.3< oat ab< s#an=>?d>;@]1:< s#an=>?d>@1:< s#an=>?d>.@]2:< s#an=>?d>.@2:< s#an=>?d>.@]3:< s#an=>?d>.@3:/ a6]1]2]3:B3.'/ b6123:B3.'/ print=>Dlnes ouse is lo#ated at ?.1=.?.1=:n>.a.b:< retum '< l Sample Input 2 4 1' 15 5 $ Sample Output Dines ouse is lo#ated at S.!;&.': (esult us; Program > "O%( SASO-(S > as been su##ess=ully ee#uted
[rade e Steel A #ertain grad one #ondition o= steel is graded a##ording to te =olloing #onditions. Tardness must be greater tan 5' Carbon #ontent must be less tan '.!. ensile strengt must be greater tan 5''. e grades are as =ollos/ [rade is 1' i= all tree #onditions are met [rade is & i= #ourse/ C Sub0e#t Code/ e #onditions i: and ii: are met. [rade is $ i= #onditions ii: and m: are met. [rade is ! i= #onditions i: and m: are met [rade is i= only is met. [rade is 5 i= none o= tree #onditions are met. Mrite a program; i= te user gi*es *alues o= ardness; #arbon #ontent and tensile strengt o= te steel under #onsideration and display te grade o= te steel. Sour#e Code 7in#lude8stdlo.9 maln: l lnt t/ s#an=>?d>;@t:< ilet++: t Int ardness; ts; oat #arbon/ .. ? s#an= Bod ?= grade< d; @ardness;@#arbon;@ts:< i= ardness95': @@ #arbon8'.!: @@ ts95'':: print=>[rade 1On>:< else i= ardness95': @@ #arbon8'.!:: print=V[rade &n>:< else i= #arbon8'.!: @@ ts95'':: print=>[rade $n>:< else i= ardness95': @@ ts95'':: print=>[rade !n>:< else i= ardness95': QQ #arbon8'.!: QQ ts95'':: print=>[rade n>:< else print=>[rade 5n>:< l l Sample Input 2 53 '.! 5'2 55 ' 54&& Sample Outpu [rade 1' [rade & (esult us; Program t > [rade e Steel > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . [reedy puppy uiK is a little dog. Uut despite te =a#t e is still a puppy e already Knos about te pretty tings tat #oins are. Te Knos tat =or e*ery #oin e #an get *ery tasty bone =rom is master. Te belie*es tat some day e ill =ind a treasure and a*e loads o= bones. And Wnally e =ound someting interesting. A ooden #est #ontaining - #oinsJ Uut as you sould remember; uiK is 0ust a little dog; and so e #ant open it by imsel=. A#tually; te only ting e #an really do is barKing. Te #an use is barKing to attra#t nearby people and seeK teir elp. Te #an set te loudness o= is barKing *ery pre#isely; and tere=ore you #an assume tat e #an #oose to #all any number o= people; =rom a minimum o= 1; to a maimum o= . Men people #ome and open te #est tey di*ide all te #oins beteen tem in su# a ay tat e*eryone ill get te same amount o= #oins and tis amount is maimal possible. I= some #oins are not used tey ill lea*e it on te ground and uiK ill taKe tem a=ter tey go aay. Sin#e uiK is #learly not a =ool; e understands tat is pro=it depends on te number o= people e ill #all. Mile uiK orKs on is barKing; you a*e to =ind te maimum possible number o= #oins e #an get. Input e =irst line o= te input #ontains an integer denoting te number o= test #ases. a# o= net lines #ontains 2 spa#e+separated integers/ - and ; =or tis test #ase. Output "or ea# test #ase output one integer + te maimum possible number o= #oins uiK #an get. Constraints 1 X X 5' 1 X -; X 1'5 In te =irst eample e sould #all to people. a# o= tem ill taKe 2 #oins and tey ill lea*e 1 #oin =or uiK. ln te se#ond eample e sould #all 3 people Sour#e Code 7in#lude8stdlo.9 int main: lnt t;m;n< s#an=>?d>;@t:< ilet++: int ma 6 '< s#an=>B89d?d>.@m;$.n:< int ii =ori62?dn>;ma:/ l retum '/ l Sample Input 2 52 113 Sample Output 1 2 (esult us; Program > [reedy puppy > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . \ultipli#ation =or a #ild
,eyanti daugter name is Tanni; se as studying 1st Standard in a s#ool. Tarinis ome orK =or te tird day is to \ultipli#ation o= to numbers; elp Tarini to sol*e te problem. Sour#e Code 7in#lude8stdQo.9 Int maln: l oat a;b.#< s#ant>?=>; @a:< s#an=>?=V; @b:/ #6aZb< print=>multipIi#ation o= te to numbers is B.2=>;#:< retum O< : Sample Input 12 1' Sample Output multipli#ation o= te to numbers is 12'.'' (esult us; Program >\ultipli#ation =or a #ild as been su##ess=ully ee#uted
#ourse/ C Sub0e#t Code/ . PLACI-[ T "LA[ POS e sape o= te #ollege ground is SYuare. "or te Independen#e day "lag Toisting "un#tion; it as been de#ided to pla#e te =lag post at te ea#t #enter o= te ground. Can you please elp tem in pla#ing te =lag post at te ea#t #enterX [i*en te #oordinates o= te le=t bottom *erte o= te sYuare ground and te lengt o= te side; you need to rite a program to determine te #oordinates o= te #entre o= te ground. _Assumption Lengt o= te side is alays e*en^ Input "ormat/ input #onsists o= 3 integers. e =irst integer #orresponds to te +#oordinate o= te le=t bottom *erte. e se#ond integer #orresponds to te y+#oordinate o= te le=t bottom *erte. e tird integer #orresponds to te lengt o= te sYuare. Sour#e Code 7in#lude8stdio.9 int main: int ;y;l< s#an=>?d>;@^< s#an=>?d>;@y:< s#an=>?d>.@l:/ 6lB2:< 6yQB2:< print=>#entre o= te ground is at?d.?d:>;;y:< retum '/ l Sample Input 4 ' a Sample Output #entre o= te ground is at$;4: (esult us; Program > PLACI-[ T "LA[ POS > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/
. Pogo Sti#K ,ump (a0u li*es in a #olony. On is &t birtday; is =ater gi=t im a Pogo Sti#K. Te is so e#ited to play it pogo sti#K. e pogo sti#K mo*es one unit per 0ump. Te anders around is ouse 0umping it pogo sti#Ks. Te ants to so te pogo sti#K to is =riends and de#ide to go using pogo sti#Ks. Mrite a program to =ind number o= 0umps needed to rea# is =riends ouse. Assume tat (a0us ouse is in te lo#ation 3;4:. Input and Output "ormat/ Input #onsists o= to integers ; y. e and y #orresponds to and y #oordinates o= is =riends ouse. Output is an integer + te number o= 0umps e needs to rea# is =riends ouse. Sour#e Code 7ln#lude8stdlo.9 7in#lude8mat.9 int maln: = lnt 1 63;y1 64;2.y2< oat poer.poer1.poer2;sYr< s#an=>?d>;@2:< s#an=>?d>;@y2:< poer16po2+1 :;2:< poer26poy2+y1:;2:< poer6p'er1 poer2< sYr6sYrtpoer:< print=>(a0u needs ?.'= 0umps>;sYr:/ retum '/ l Sample Input 5 Sample Output (a0u needs 3 0umps (esult us; Program > Pogo Sti#K ,ump > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . P(O"I CALC%LAO( a# Sunday; a nespaper agen#y sells #opies o= a #ertain nespaper =or (s.a per #opy. e #ost to te agen#y o= ea# nespaper is (s.b . e agen#y pays a =ied #ost =or storage; deli*ery and so on o= "ts.1'' per Sunday. e nespaper agen#y ants to #al#ulate te pro=it obtained on Sundays. Can you please elp tem out by riting a C program to #ompute te pro=it gi*en ; a and b. Input "ormat/ Input #onsists o= 3 integers ; a and b. ] is te number o= #opies sold; a is te #ost per #opy and b is te #ost te agen#y spends per #opy. Sour#e Code 7Qn#lude8stdio.9 lnt main: l lnt #'ples;#ost.spent;pro=it0inalproWt< s#an=>?d>;@#opies:< s#an=>?d>.@#ost:/ s#an=>?d>;@spent:< pro=it6#opies#ost:+#opiesZspent::< =inalpro=lt6proWt:+1''< print=>e pro=it obtained is (s6B9dn>.=inaQpro=lt:< it=inalpro=it66+1'':
print=>in*alid input>:/ retum O/ l Sample Input 1''' 2 1 Sample Output e pro=it obtained is (s6&OO (esult us; Program V P(O"I CALC%LAO( > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . (adius o= a Cir#le \adan is andling matemati#s to $t grade. Te taugt area and perimeter o= geometri# sapes to is students. Te tougt to gi*e a test based on triangle and #ir#les.e tasK is to #al#ulate radius o= te #ir#le tat is ins#ribed in triangle gi*en te tree sides o= te triangle. Te as set 2' Yuestions and e is tired o= preparing anser Keys.Mrite a program to =ind te radius o= te #ir#le ins#ribed in a triangle. Input and Output "ormat / Input #onsists o= tree integers a; b and #. e tree integer #orresponds to tree sides o= a triangle Sour#e Code 7ln#lude8stdlo.9 7in#lude8mat.9 int maln: int a.b;#< =loat s;rsY;r< s#an=>BodnV;@a:< s#an=>?dn>;@b:I s#ant>?d>.@#:< s6ab#:J2< rsY6s+a:s+b:s+#:Bs:< r6sYrtrsY:< print=>e radius o= te #lr#le is6?.2=n>;r:< retum '< : Sample Input 3 4 5 Sample Output e radius o= te #ir#le is61.'' (esult us; Program > (adius o= a Cir#le> as been su##ess=ully ee#uted
#ourse/ C Sib0e#t Code/ . S#anning Int and string by retailer Taris retail sop e need a so=tare to get te name o= te produ#t and #ost o= te produ#t and generate a bill =or tat one produ#t i# #onsist o= name o= te produ#t and #ost o= tat produ#t. Sour#e Code 7in#lude8stdIo.9 Int maln: l #ar #_2'^<
lnt a< s#an=>B89s>.#:< s#an=>?d>;@a:I print=>P(OD%C -A\/B89s>#:/ printt>nCOS/?d>;a:/ retum O< l Sample Input soap 121 Sample Output P(OD%C -A\/soap COSI121 (esult us; Program >S#anning Int and string by retailer> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Splitting into eams During te Pysi#al du#ation our; P sir as de#ided to #ondu#t some team games. Te ants to split te students in te #lass into eYual sied teams. In some #ases; tere may be some students o are le=t out =rom teams and e anted to use te le=t out students to assist im in #ondu#ting te team games. "or instan#e; i= tere are 5' students in te #lass and i= te #lass as to be di*ided into ! eYual sied teams; ! students ill be tere in ea# team and 1 student ill be le=t out. P sir asKs your elp to automate tis team splitting tasK. Can you please elp im outX Input "ormat/ Input #onsists o= 2 integers. e =irst integer #orresponds to te number o= students in te #lass and te se#ond integer #orresponds to te number o= teams. Sour#e Code 7in#lude8stdio.9 Int main: l Int students.teams.team;le=t/ s#an=>B89d>.@students:< s#an=>?d.@teams:< =eam6students1teams< le=t6studentsB9teams/ print=>e number o= students in ea# team is Bod and le=t out is ?d>.team.le=t:< retum '/ l Sample Input ' $ Sample Output e number o= students in ea# team is ! and le=t out is 4 (esult us; Program > Splitting into eams> as been su##ess=ully ee#uted
$1 "inding St A #ertain grad one #ondition o= steel is graded a##ording to te =olloing #onditions. Tardness must be greater tan 5' Carbon #ontent must be less
tan '.!. ensile strengt must be greater tan 5''. e grades are as =ollos/ [rade is 1' i= all tree #onditions are met [rade is & i= #ourse/ C Srb0e#t Cod . ee e #onditions i: and ii: are met. [rade is $ i= #onditions ii: and m: are met. [rade is ! i= #onditions i: and m: are met [rade is i= only is I [rade met. [rade is 5 i= none o= tree #onditions are met. Mrite a program; i= te user gi*es *alues o= ardness; #arbon #ontent and tensile strengt o= te steel under #onsideration and display te grade o= te steel. Sour#e Code 7in#lude8stdlo.9 maln: l lnt t/ s#an=>?d>;@t:< ilet++: l Int ardness; ts; oat #arbon/ .. ? s#an= ?d ?= grade< d; @ardness;@#arbon;@ts:< ll ardness95': @@ #arbon8'.!: @@ ts95'':: print=>[rade 1On>:< else i= ardness95': @@ #arbon8'.!:: print=V[rade &n>:< else i= #arbon8'.!: @@ ts95'':: print=>[rade $n>:< else i= ardness95': @@ ts95'':: print=>[rade !n>:< else i= ardness95': QQ #arbon8'.!: QQ ts95'':: print=>[rade n>:< else print=>[rade 5n>:< l l Sample Input 2 53 '.! 5'2 55 ' 54&& Sample Outpu [rade 1' [rade & (esult us; Program t > "inding Steel [rade> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Summing te - series ou are gi*en a seYuen#e ose nt nt term is n6n28n861:2n86n286n861:2 ou a*e to e*aluate te series Sn6123
86nSn612386n "ind Snmod1'&!:Snmod1'&!:. Input "ormat e =irst line o= input #ontains ; te number o= test #ases. a# test #ase #onsists o= one line #ontaining a single integer nn. Output "ormat "or ea# test #ase; print te reYuired anser in a line. Constraints 186861'186861' 186n861O>1186n861'>1 Sour#e Code 7in#Qude 8stdio.9 7ln#lude 8string.9 7in#lude 8mat.9 7in#lude 8stdlib.9 7ln#lude 8tgmat.9 int main: N int #ases< s#an=>Bed. @#ases:< lnt i< =or i6O/i8#ases/i:N long int ntterm< s#an=>?ld>; @ntterm:< long long int modulo 6 po1'; &: !< print=>?lldn>. long long int:polntterm ? modulo: .2?modulo:Bomodulo: 1 l retum '< l Sample Input 2 21 Sample Output 4 1 (esult us; Program > Summing te - series> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Sum o= palindromi# numbers A number is #alled palindromi# i= its de#imal representation is a palindrome. ou are gi*en a range; des#ribed by a pair o= integers L and (. "ind te sum o= all palindromi# numbers lying in te range _L; (^; in#lusi*e o= bot te etrema. Input e =irst line o= te input #ontains an integer denoting te number o= test #ases. e des#ription o= test #ases =ollos. e =irst line o= ea# test #ase #ontains a pair o= spa#e separated integers L and ( denoting te range =or i# you are reYuired to =ind te sum o= te palindromi# numbers. Output "or ea# test #ase; output a single line #ontaining te sum o= all te palindromi# numbers in te gi*en range. Constraints 186861'' SubtasK 1 34 points: / 186L86(86='3 SubtasK 2 points: / 186L86"K61'5 planation ample #ase 1. e palindromi# numbers beteen 1 and 1' are all numbers e#ept te number 1'. eir sum is 45. Sour#e Code 7ln#lude 8stdio.9 lnt maln: l int t< s#an=>?d>;@t:/ ilel++: l lnt a;b<
s#an=>?d B89d>;@a;@b:< int i< long int s6'< =ori6asum ls B9ldn>;s:< l return '< l Sample Input 2 1 1' 123 15' Sample Output sum is 45 sum ls 2!2 (esult us; Program > Sum o= palindromi# numbers > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code . T( IDIOS A0ay; Uinoy and Candru ere *ery #lose =nends at s#ool ey ere *ery good Qn \atematl#s and tey ere te pet students o= mily \am. err gang as Knon as 3+ldlots A0ay; Umoy and Candru lQ*e Qn te same lo#alrty A ne student Dmes QoQns teQr #lass and e anted to be =nends Qt tem Te asKed Umoy about as ouse address Umoy anted to test Dmess matematl#al sKrlls Uinoy told Dines tat Qs ouse Qs at te mQdpoQnt o= te lQne ^OlllItlg A0ays ouse and Candrus ouse Dmes as puled Can you elp Dines outZX [en te #oordlnates o= te 2 end pomts o= a lme 1;y1: and 2 y2:; rQte a C program to =md te mldpomt o= te line. Input "ormat Input #onsusts o= 4 mtegers e =lrst Integer #orresponds to 1 e se#ond Integer #orresponds to y1 e trrd and =ourt integers #orrespond to 2 and y2 respe#tl*ely Sour#e Code 7Qn#lude8stdlo.9 rm maln: = lnt ]1 ;]2;1 .2< =loat m1.m2;m3< s#an=>?d;@]1:< s#an=>?d>;@1 :< s#an=>B89d>;@]2:< s#an=>?d>.@2:< m16]1]2:B2.'< m3612< m26m3B2< print=>nUinoys ouse ls lo#ated atB9 1= B' 1=: m= m2: retum '/
l Sample Input 24 1'15 Sample Output Uinoys ouse is lo#ated at ' & 5: (esult us; Program > T( IDlOS> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Lu#y Lu#y is #elebrating er 15t birtday. Ter =ater promised er tat e ill buy er a ne #omputer on er birtday it se sol*es te Yuestion asKed by im. Te asKs Lu#y to Wnd eter te year on i# se ad born is leap year or not. Telp er to sol*e tis pule so tat se #elebrates er birtday appily. I= er birt year is 2'1 and it is a leap year display 2'1 is a leap year.X lse display 2'1 is not a leap year and #e#K it oter leap year #onditions Sour#e Code 7ln#lude 8stdio.9 lnt maln: l Int year< BBprint=>nter a year to #e#K i= it is a leap yearn:< s#an=>?d; @year:< I= year?4'O 66 ': prlnt=V?d is a leap year. year:< else it yearBh1'' 66 ': printi>?d is not a leap year>; year:< else ii year?4 66 ' : print=>B9d is a leap year. year:< else print=>?d is not a leap year>; year:< retum O/ l Sample Input 1&'' Sample Output 1&'' is not a leap year (esult us; Program > Lu#y > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . Uiased Candan Candan is an etremely biased person; and e disliKes people o =ail to sol*e all te problems in te inter*ie e taKes =or iring people. ere are n people on a day o #ame to be inter*ieed by Candan. Candan rates e*ery #andidate =rom ' to 1'. Te as to output te total ratings o= all te people o #ame in a day. Uut; eres te problem/ Candan gets etremely =rustrated en someone ends up s#oring a ' in te inter*ie. So in =rustration e ends up remo*ing te #andidate o s#ored tat '; and also remo*es te #andidate o #ame be=ore im. I= tere is no #andidate be=ore te one o s#ores a '; e does noting.ou*e to =ind te summation o= all te ratings in a day =or Candan. Input #onstraints/ e =irst line o= input
ill #ontain an integer n. e net n lines ill #ontain an integer; ere te it integer represents te rating o= te it person. Output #onstraints/ Print te reYuired sum. Constraints/ 1 86 n 86 5 1'3 ' 86 )alue o= ratings 861 ' Sour#e Code 7in#Iude 8stdio.9 int maln: i int n;i;sum6O/ s#an=>?d>.@n:1 int a_n^/ =ori6'?d>;@a_i^:<: lln661:Nprint=>?d>;a_'^:?d>;sum:< l retum '/ l Sample Input O,OOOQ,%l Sample Output 2 (esult us; Program > Uiased Candan> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Doll So In London; *ery year during Dasara tere ill be a *ery grand doll so. People try to in*ent ne ne dolls o= di==erent *arieties. e best sold dolls #reator ill be aarded it #as prie . So people broKe teir ead to #reate dolls inno*ati*eiy .noing tis #ompetition; \r. LoKPaul tried to #reate a doll i# sings only en a e*en number is pressed and te number sould not be ero and greater tan 1''. So rite a C program to elp mr. LoKpaul to in. Input =ormat/ lnput #onsists o= 1 integer i# #orresponds to -umber pressed by te user to te doll. Output =ormat / Display eter te doll ill a sing or not. Output #onsists o= te string >Doll ill sing> or >In*alid number> (e=er sample input and output =or =urter =ormatting spe#i=i#ations. Sour#e Code 7ln#lude8stdio.9 Int main: lnt < #ar a_2'^6Doll ill sing.b_2'^6>ln*alld -umber>< s#an=>?d>;@:< i=81'' @@ ?266' @@ l6': N
prinl=>?sn>;a:< I else N plZllll>BoHll>;D:G : return '< c Sample Input 5 Sample Output Doll ill sing (esult us; Program > Doll So > as been su##ess=ully ee#uted
Course/ C X<.lb^$Cl Code/ . Leap year (aguraman is te orrisome as ell as #aring =ater o= is only daugter barani ;togeter tey li*e a #alm and #ontent li=e. O*er te years as Uarani gros up ; (aguramam got more and more atta#ed to is daugter barani. As bi0arani is *ery intelligent and brigt in er studies. Se got a good pla#ement o==er in #anada. (aguraman as so#Ked.Altoug te tougt o= being separated =rom is dead daugter is eartbreaKing. (aguraman earily a##epts. Uarani promises er tat se ill #ome ome on#e e*ery leap year. (aguraman as aiting =or is daugter arri*al. Te doesnt Kno i# is leap year. So rite a C program to elp "lagumaran to =ind a eter te year is a leap year. Input =ormat/ Input #onsists o= single integer i# #orresponds to a year Output =ormat 1 Displays eter te gi*en year is a leap year or not. (e=er sample input and output =or =urter =ormatting spe#i=i#ations. Sour#e Code 7ln#lude 8stdio.9 int maln: t Int a/ BBprint=>nter a year to #e#K i= it is a leap yearn>:< s#an=Bad>; @a:< i= a?466':@@a?1''l6':^_a?4''66'::: l print=>Leap ear>:< c else l print=>-ot a Leap year>:< c retum O/ l Sample Input 2''4 Sample Output Leap ear (esult us; Program >Leap year > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Approimate )alue Pineas and "erb o li*e in te =i#tional ton o= dan*ille ;tinK and do inno*ati*ely on eeKends. *ery day te boys embarK on some grand ne pro0e#t; i# annoys teir #ontrolling sister #anda#e; o tries to bust tem. One sunday tey ere bot sitting under a tree in teir ba#K yard. ey de#ide to in*ent a ma#ine i# ould allo us to enter 2 numbers it ould say eter one o= te entered number is an appropriate *alue o= te oter number entered. ey de#ide to insert a program #ode in te ma#ine. A number is said to be an approimate *alue o= te oter i= tey di==er by utmost '.5. So rite a C program to =ind eter te gi*en number is approimate number o= oter. Input "ormat/ Input #onsists o= to =loat type numbers Output =ormat/ Displays eter te number is approimate or not. Sour#e Code 7ln#lude8stdio.9 Int maln: int .y;#< s#an=>?dBod;@@y:/ i=y9]: I #6y+< I else I #6+y< 1 l=#86'.5: N print=>ApproImate number>:< : [IS[ I prinl=>-ot an Approimate number>:< 1 return '< : Sample Input 14 14.3 Sample Output Approimate number (esult us; Program > Approimate )alue > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . A asK A tasK is gi*en to 3 persons to #omplete it itin a parti#ular time. I= te person e#eeds te time limit e ill be disYuali=ied . Only tose o #omplete it itin te gi*en time limit is YualiWed. Among te Yuali=ied persons. te person o #omplete te tasK =irst ill be rearded. Mrite C program to =ind te person o is rearded.Mrite a C program to =ind te person o is rearded. Input "ormat/ "irst Input #orresponds to te time limit =or te tasK in ours . Se#ond; tird and =ourt input #orresponds to te number o= ours taKen by te =irst; se#ond and tird persons respe#ti*ely to #omplete te tasK. Output
=ormat/ Display te person o #ompletes =irst. Sour#e Code 7ln#lude8stdlo.9 int main: int a;b;#;d< s#an=>B9dB89d?d?d>;@a;@b;@#;@d:< l=b8a@@#9b@@d9b: l print=>"lrst person insll>:< l else i=#8a@@b9#@@d9#: l prin==>Se#ond person lnsll:< l else i=d8a@@b9d@@#8d: l prlnt=>ird person insllV:< l else i=b9a@@#9a@@d9a: l print=>-o person insll>:< l return '/ l Sample Input l,9%fF O Sample Output Se#ond person insll (esult us; Program > A asK > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Ulood UanK A team =rom S(\ (otara#t #lub ad planned to #ondu#t rally to #reate aareness among te #ennai people to denote blood. ey #ondu#ted te rally su##ess=ully. \any o= te #ennai people realise it and #ame =onr*ard to donate teir blood to near by blood banK. e eligibility #riteria =or donating blood is people sould be abo*e 1$ and is er eigt sould be abo*e 4'. ere as a uge #rod and sta== in blood banK =ound it di==i#ult to manage te #rod. So tey de#ided to Keep a system and asK te people to enter teir age and eig in a system. I= a person is eligible e Bse ill be alloed inside. Mrite a C program and =eed it to te system to =ind eter a person is eligible or not. Input =ormat/ Input #onsists o= 2 integers i# #orresponds to age and eigt o= a person respe#ti*ely. Output "ormat/ Display eter person is eligible or not. Sour#e Code 7ln#lude8stdlo.9 Int maln: int y< s#ant>B89d>;@:< s#an=>?d;@y:< it91$@@y94': N print=>ligible to donate>:< c
else N prlntt>-ot ligible to donate>:< l return '< l Sample Input 1& 5' Sample Output ligible to donate (esult us; Program > Ulood UanK> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Ce= and Ualls Ce= as bougt ten balls o= =i*e #olours. ere are to balls o= ea# #olour. Ualls o= same #olour a*e same eigt. Let us enumerate #olours by numbers =rom 1 to 5. Ce= Knos tat all balls; e#ept to o= same #olour:; eig ea#tly one Kilogram. Te also Knos tat ea# o= tese to balls is ea#tly 1 Kg ea*ier tan oter balls.ou need to =ind te #olour i# balls are ea*ier tan oters. o do tat; you #an use me#ani#al s#ales it to eiging pans. As your s#ales are *ery a##urate; you #an Kno te ea#t di==eren#e o= eigts o= ob0e#ts =rom =irst and se#ond pans. "ormally; te s#ales ill gi*e you te di==eren#e signed di==eren#e: o= eigts o= te ob0e#ts put into te =irst pan and te se#ond pan. See te =olloing eamples =or details I= you put to balls o= te same #olour on your s#ales; ea# ball to one pan; te s#ales ill tell you tat di==eren#e is >'>. Uut i= you put into te =irst pan some balls o= total eigt 3 Kg; and into te se#ond pan o= 5 Kg; ten s#ales ill tell you be#ause te se#ond pan is 2 Kg ea*ier tan =irst Similarly; i= you put 5 Kg eigt in =irst pan and 3 Kg in te se#ond pan; ten s#ale ill tell you >2> as =irst pan is 2 Kg ea*ier tan se#ond. Input @ Output e intera#tion pro#ess a*e to pases. At =irst pase you per=orm seYuen#e o= eigings on te me#ani#al s#ales. At te se#ond pase you sould output te #olour o= te ea*ier balls o use te me#ani#al s#ales; you sould print >1>itout Yuotes: and ten print to lines; te =irst line ill des#ribe te enumeration o= #olours o= balls on te =irst pan and se#ond line sould tat o= se#ond pan o des#ribe some pan; you need to print one integer n + te number o= balls you put in tis pan; =olloed by n spa#e+separated integers + #olours o= te balls you put in tis pan On#e you a*e printed reYuired data; you #an read =rom te standard input one integer + te di==eren#e o= eigts o= te =irst and te se#ond pans o output te #olour o= te ea*ier balls; you sould print >2>itout Yuotes: and one integer in net line + #olour o= te ea*ier balls. Constraints a# #olour you print sould be beteen 1 and 5. Sour#e Code 7ln#lude8stdlo.9 int main: = int < print=>1n>:< ==lusstdout:< prlnt=>3 1 2 2n>:< ==lusstdout:<
prlnt=3 3 4 4n:< ==lusstdout:< s#an=?d>;@:/ print=>2n>:< ==lusstdout:< i=66': N print=>5V:1 ==lusstdout:< c else l=661: l print=>1>:< ==lusstdout:< l else l=662: l print=>2>:/ ==lusstdout:< c else Q=]661: l Pi>>>3>:< ==lusstdout:< c eQHe Q=]66+2: i print=>4>:/ ==lusstdout:< c return '< l Sample Input 1 Sample Output 1 3122 3344 2 1 (esult us; Program > Ce= and Ualls > as been su##ess=ully ee#uted
#ourse/ C Strb0e#t Code/ . Pattern 1 Mrite a program to generate a =olloing stru#ture/ hhhhh hhhhh hhhhh hhhhh hhhhh Sour#e Code 7in#lude8stdlo.9 lnt maln: t int num.r;#< BBprint=>nter loop repeat numberros:/ >:< s#an=?d>;@num:< =orr61/ num96r/ r: N =or#61< #86num/ #: prinm>h>9<
printt>n:/ c return '< l Sample Input 2 Sample Output hh hh (esult us; Program > Pattem 1 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Pattern 2 Mrite a program to generate a =olloing 7s triangle/ 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 Sour#e Code 7in#lude8stdio.n9 lnt maln: l int num.r61;#;sp< BBprint=>nter loop repeat numberros:/ >:1 s#an=?d>;@num:< =or/ num961/ num++;r: l =orsp6r< sp91/ sp++: P>>>> >ll =or#61< #86num< #: print=>7>:< print=>n:< l return '< l Sample Input s Sample Output 77777 77477 777 77 7 (esult us; Program > Pattem 2 > as been su##ess=ully ee#uted
#ourse/ C Sgb0e#t Code/ . Pattern 3 Mrite a program to generate a =olloing hs triangle/ h h h h h h h h h h h h h h h Sour#e Code 7in#lude8stdio.9 int main: N int num.#/ BBprint=>nter loop repeat numberros:/ >:1 s#an=?d>;@num:< =orI num961/ num++: N
=or#61/ #86num/ #: pr1nm>h>9< print=>n:/ c return '< i Sample Input ! Sample Output hhhhhhh hhhhhh hhhhh hhhh hhh hh h (esult us; Program > Pattem 3 > as been su##ess=ully ee#uted
#ourse/ C =ub0e#t Code/ . Pattern 4 Mrite a program to generate a =olloing 7s triangIe/+ 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 Sour#e Code 7in#Qude8stdio.9 Int main: N int num.r;#< BBprint=>nter loop repeat numberros:/ >:1 soan=?d>;@num:< =orr61/ num96r/ r: N =or#61/ #86r< #: pnnt=>7>:/ print=>n>:/ c return '< : Sample Input 3 Sample Output 7 77 777 (esult us; Program > Pattem 4 > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . InBout \s.irtiga; te =a#ulty andling programming lab =or you is *ery stri#t. our seniors a*e told you tat se ill not allo you to enter te eeKs lab i= you a*e not #ompleted atleast al= te number o= problems gi*en last eeK. \any o= you didnt understand tis statement and so tey reYuested te good programmers =rom your bat# to rite a # program to =ind eter a student ill be alloed into a eeK lab gi*en te number o= problems gi*en last eeK and te number o= problem sol*ed
by te students in tat eeK. lnput =ormat/ lnput #onsists o= 2 integers. e "irst integer #orresponds to te number o= problems gi*en and te se#ond integer #orresponds to te number o= problems sol*ed. Output =ormat/ Output #onsists o= te string >l-> or >O%> (e=er sample input and output =or =urter =ormatting spe#i=i#ations. Sour#e Code 7ln#lude8stdlo.9 lnt maln: int .y.< #ar a_2O^6>l->;b_2'^6>O%>< s#an=>B89dB9dV;@.@y:< 6B2/ i=y9: N print=>?sn>.a:< c else N prlnlt>?sn>.b:< l return '< l Sample lnput $ 3 Sample Output O% (esult us; Program > InBout > as been su##ess=ully ee#uted
Course/ C 11 Sub0e#t Code/ . Pattern 5 Mrite a program to generate a =olloing hs triangle/ h h h h h h h h h h h h h h h Sour#e Code 7in#lude8stdio.9 int main: l int num.r;#;sp< BBprintt>nter loop repeat numberros:/ >:1 s#an=?d>;@num:< =orr61/ num96r/ r N 9 =orsp6num+r/ sp961/ sp++: prin> >1/ =or#61/ #86r< #: prmm>h>9< printt>n:< c return '< l Sample Input 5 Sample Output h
hh hhh hhhh hhhhh (esult us; Program > Pattem 5 > as been su##ess=ully ee#uted
#ourse/ C Wrb0e#t Code/ . Pattern Mrite a program to generate a =olloing numbers stru#ture Sour#e Code 7in#lude8stdlo9 lnt maln: l int num.r;#< BBprint1>nter loop repeat numberros:/ >:< s#an=?d>;@num:< =orr61/ num96r< r: N =or#61< #86num< #: prlnt=>?d>.#:< print=>n>:< l return '< l Sample Input 5 Sample Output 12345 12345 12345 12345 12345 (esult us; Program > Pattem > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Uetter or -ot One #riteria =or e*aluating 2 di==erent #olleges is based on te student strengt. Mrite a C program to #ompare 2 #olleges based on te student strengt Input =onnat/ Input #onsists o= 2 integers. e =irst integer #orresponds to te -umber o= students during te year o= establisment o= #ollege 1 and te se#ond integer #orresponds to te -umber o= students during te year o= establisment o= #ollege 2 Output =ormat/ Output #onsists o= te string >College 1 is Uetter> or >College 2 is Uetter>. (e=er sample input and output =or =urter =ormatting spe#i=i#ations. Sour#e Code 7Qn#lude8stdlo.9 lnt main: int y< #ar a_2'^6College 1 is better>.b_2O^6>CoQlege 2 is betterV< s#an=>?dB6d>;@.@y:< i=y9:
N prlnt=>B89sn>.b:< l else N prInt=>?sn>;a:< l return '< l Sample Input 1 ''' 12'' Sample Output College 2 is better (esult us; Program > Uetter or -ot > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . -e or Old Men parents taKe teir Kids =or ngineering Counselling ; tey alays go it a pre#on#ei*ed notion tat older te #ollege; better ill be te Yuality o= edu#ation o==ered. ere is a elp desK in =ront o= te #ounselling all to tell out o= te #olleges in i# seats are a*ailable.; i# #ollege is te older one. -o a days ;engineering #ounselling goes on =or a mont and te elp desK need to =un#tion on all days. So te Dean; Admissions de#ided to automate tis tasK. Can you elp im in tis tasKX [i*en te year o= establisment o= 2 #olleges ; rite a C program to determine i# #olleges is te older one. Input =ormat/ Input #onsists o= 2 integers. e =irst integer #orresponds to te year o= establisment o= #ollege 1 and te se#ond integer #orresponds to te year o= establisment o= #ollege 2 Output =ormat/ Output #onsists o= te string >College 1 is older> or >College 2 is older>. (e=er sample input and output =or =urter =ormatting spe#i=i#ations. Sour#e Code 7ln#lude8stdlo.9 int main: int .y< #ar a_2'^6>College 1 is older>.b_2'^6>College 2 ls older>/ s#an=?d?d;@;@y:< i=8y: l prln==>?s+.n>.a:< l else l prin==>?sn>;b:< i return '2 l Sample Input 2''2 2''$ Sample Output College 1 is older (esult us; Program > -e or Old > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Semester Tolidays -ormally in all engineering #olleges; tere ill be long *a#ation a=ter e*ery e*en semester and a sort *a#ation a=ter e*ery odd semester. Input =ormat/ Input #onsists o= 1 integers i# #orresponds to te #urrent semester o= te students i.e: *en semester > Long )a#ation> ODD semester >Sort )a#ation> determine by di*idingmodulo: it 2 Output =ormat/ Output #onsists o= te string >Long )a#ation > or >Sort )a#ation>. (e=er sample input and output =or =urter =ormatting spe#i=i#ations. Sour#e Code 7ln#lude8stdlo.9 Int maQn: int .y/ s#an=>?d>;@:< y6?2/ i=8y66'9 N prlnt=>Long )a#atlon>:< l else l print=>Sort )a#ation>:/ l return '< l Sample Input Sample Output Long )a#ation (esult us; Program > Semester Tolidays > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . Lab seating arrangement ere are 2 Programming Labs . a# it a seating #apa#ity o= &'. ere are 24' students it registration numbers =rom 1 to 24'. All 24' students #annot be a##ommodated in te labs at te same time. It as been de#ided to #ondu#t teory #lass =or ' students e*ery eeK. It as been planned to #ondu#t teory #lasses =or all students it register number being a multiple o= 4. Students it registration number =rom to 1 to 12' it registration number not a multiple o= 4 need to be seated in programming lab1 and students it registration numbers =rom 121 to 24' it registration numbers not a multiple o= 4 need to be seated in programming lab ll. [i*en te registration number o= student; rite a C program to spe#i=y te lab or all in i# student need to be seated. Input "ormat/ Input #onsists o= 1 integer i# #orresponds to te registration number o= te student. Output =ormat/ Output #onsists o= string >Lab 1> or >Lab 2> or >eory session > or Xln#orre#t (egister -umberX (e=er sample input and output =or =urter =ormatting spe#i=i#ations. Sour#e Code 7in#lude8stdio.9 lnt maln:
int .y< s#ant>?d>;@:< i=]Bo466O:@@]8624':: N prlnt=>eory session>:< l else i= 961:@@812O::@@?4l6':: N prlnt=>Lab 1>:< l else i=9612' :@@ 8624'::@@ B894l6':: N prlnt=>Lab 2>:< l else N prln11>ln#orre#t (egister -umber>:/ l return '/ c Sample Input 1 Sample Output eory session (esult us; Program >Lab seating arrangement> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Se#tions I= te number o= seats alloed to a parti#ular bran# in engineering e#eeds '; ten ere ill be multiple se#tions in tat bran#. [i*en te number o= seats allotted to a bran# rite a C program to determine eter tere ill be a single se#tion or multiple se#tions Input "ormat/ Input #onsists o= 1 integer i# #orresponds to te number o= seats allotted to a bran# Output =ormat/ Output #onsists o= string >Single se#tions> or >\ultiple Se#tions> (e=er sample input and output =or =urter =ormatting spe#i=i#ations. Sour#e Code 7ln#lude8stdio.9 int maln: int i s#an=>?d>;@:< it86': l print=>SQngle Se#tions>:< l else N prlnt=>\ultIple Se#tions:< c retum O< : Sample Input !2 Sample Output \ultiple Se#tions (esult
us; Program > Se#tions > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Class (epresentati*e A student is eligible to be a #lass representati*e i= is or er attendan#e ? and marKs is greater tat &'? and e or se doesnt a*e any arrears. [i*en te attendan#e ? ;marK B89 and number o= arrears; rite a C program to determine eter a student is eligible to be a Class (epresentati*e or not. input =ormat/ input #onsists o= 2 =loat and an integer. e =irst =loat #orresponds to te attendan#e B89 and te se#ond =loat #orresponds to te per#entage o= marKs. e tird input is an integer i# #orresponds to te number o= arrears. Output =ormat / Output #onsists o= te string >ligible > or >-ot ligible> (e=er sample input and output =or =urter =ormatting spe#i=i#ations. Sour#e Code 7ln#lude8stdio.9 Int main: =loat a;b< int #< s#an=>?=>;@a:< s#an=>?=>;@b:I s#an=VB9d>;@#:< l=a9&'@@b9&O @@#66': l prlnt=>llgibleV:< i else N print=>-ot ligible>:< c return '/ i Sample Input 1''.' &.3 ' Sample Output ligible (esult us; Program V Class (epresentati*e > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . \i#Key \ouse \i#Key and \iney are to =riends . [oo=y as one o= te mi#Key enemy . Te as 0ealous o= mi#Key be#ause mi#Key as liKed by e*eryone. One day mi#Key and miney ent on to a trip. [oo=y planned to Kidnap miney. Te Kidnapped miney and Kept er in one o= te ot balloons tied up to a eigt. tere ere 5' ot balloons numbered =rom one. a# balloons ill y to a #ertain eigt. Only te numbers a*ing 3 and ! as its =a#tors #an =ly upto te eigt o= te miney balloon. mi#Key as #on=used and e didnt Kno i# numbered balloon #an =ly to miney. So rite a program to elp te mi#Key in =inding te balloon. Input =ormat/ Input #onsists o= Single Integer i# #orresponds to number printed on te balloon. Assume tat te input
*alue is beteen 1 and 5' Output =ormat / Display eter te gi*en Ualloon ill =ly to \iney or -ot (e=er sample input and output =or =urter =ormatting spe#iW#ations. Sour#e Code 7ln#lude8stdio.9 int maln: int < s#an=>?d>;@:< l=Bo366':@@?!66O:: N print=>is balloon #an =ly to miney>:< c else l prlnt=>is balloon #annot =ly to miney>:< I return '< l Sample Input 24 Sample Output is balloon #annot =ly to miney (esult us; Program > \i#Key \ouse V as been su##ess=ully ee#uted
#ourse/ C Sib0e#t Code/ . Palindrome #ount + String Count [i*en a string S; #ount te number o= non empty sub strings tat are palindromes A sub string is any #ontinuous se uen#e o= + Y #ara#ters in te string. A string is said to be palindrome; i= te re*erse o= te string is same as itsel=. o sub strings are di==erent i= t . . . . . . . . ey o##ur at di==erent positions in S Input Input #ontains only a single line tat #ontains string S. Output Print a single number; te number o= #ount in te string. Constraints 1 86 QSQ 86 5' S #ontains only loer #ase latin letters; tat is #ara#ters a to . Sour#e Code 7ln#lude8stdio.9 int maln: l lnt n;l;0;Q< #ar str_51^< long int dp_51^_51^< s#ant>?s>;str:< n6O< =orQ6'/str_i^l6>'/i: n< =orl6O/i8n+1/i: dp_i1^_i^6'< tori6'
i=s=r_i^66str_0^: dP_illll6dPlilll+11dPli1^ll^1 < else dP_1_il6dP_i1%+1^dPli1^%^F1P_Q1T1411 l l prlnt=>-umber o= palindromi# substrings/?ld>;dp_'^_nE1^:< return '< l Sample Input MLCO\OS(\%-I)(SI Sample Output -umber o= palindromi# substrings/14t (esult us; Program > Palindrome #ount + String Count> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . [ame o= Strings Tars and AKsara are playing te [ame o= Strings. is game is a simple one and is played as a team. Uot te players o= a team ill be gi*en a string respe#ti*ely. At te end o= tis game; e*ery team is reYuired =ind out te lengt o= te longest string S su# tat te strings gi*en to ea# o= te team members is a subseYuen#e o= S andS #ontains no *oels. Telp Tars and AKsara in =inding out te reYuired lengt. Input/ Input #onsists o= a single line #ontaining to spa#e separated strings. Output/ e lengt o= te longest string tat satis=y te gi*en #onditions. Constraints/ 1 X lengt o= string X 5''' planation e reYuired string is >ng>. i= te #onstraint o= te string S not #ontaining *oels is remo*ed; tis be#omes te #lassi#al Longest Common SubseYuen#e LCS: problem. "or readers o are not =amiliar it LCS problem; tey are en#ouraged to go troug te =olloing linK i# eplains te problem as ell to o to #ome up it te solution. ttp/BBen.iKipedia.orgBiKiBLongest#ommonsubseYuen#eproblem One #an see tat te LCS o= te input to strings #an ne*er #ontain any *oels; en#e; it is redundant to a*e *oels in te original string. -o; i= e remo*e te *oels =rom te input strings; te problem is to =ind te lengt o= te LCS o= te edited strings. One #an use te same approa# des#ribed in te abo*e iKi linK to implement te solution. Sour#e Code 7ln#lude 8stdio.9 7de=lne \A]- 5'''1 #ar str1_\A]-^< #ar str2_\A]-^< int str1Len; str2Len< 7de=ine \A]A;U: A:9U:XA:/U:: int DPArrN\A]-^_\A]-^/ int #StrLen#ar Z str1: l int i6'< ilestr1 _i^ l6 ': l< return ll l int ls)oel#ar #:
int res 6 '/ >` 66 a ll 86 66 e ll 86 66 i ll # 6 ' ll 86 66u9 1Q # 66 AZ QQ # 66 5 QQ 8< 66 Q QQ ` 66 +' QQ ` 66u:: res 6 1< return res l int runDPint len1; int len2: i int i;0< int ma 6'/ =orl6'/ i8Qen11< i: DPArr_l^_'^ 6 '< =orl6'/ i8Qen21/ i^ DPArr_'^_i^ 6 '< =or i61< i8len11:/ i: N =or 061/ ^8len21:< 0: i i=str1 %+1^ l6 str2_0+1^: DPArr_i^_^^ 6 \A]DPArr_i+1^_0^. DPArr_l^_0+1^:/ else i=ls)'elstr1_i+11:: DPArr_Q^_Q^ 6 \A]DPArr_l+1^_0^; DPArrNl^_Q+1^:< else l DPArr_i^Q0^ 6 DPArr_i+1^_0+1^ 1< c l i 7lt ' prQnt=>n >:/ =or i6'< i8Qen2:< l: l print=>?# >; str2_i^:< c prlnt=>n V:1 =or i6'< i8len11:/ i: N l=l961: prlnt=>?# >; str1_l+1^:/ =or i6'/ 08len21:< 0: Nplll>It=>Bed >; DPArr_i^_0^:< mmr>n:/ =lendi= return DPArr_Qen1^_len2^< i int maln: s#an=?s>. str1 :< s#an=>?s>. str2:< strt Len 6 #StrLenstr1:< str2Len 6 #StrLenstr2:/ print=>?d>; runDPstr1 Len. str2Len::< return '< l Sample Input TDDS 3.$DbSS Sample Output 3 (esult
us; Program >[ame o= Strings > as been su##ess=ully ee#uted
Sub0e#t Code/ . Sum o= *e Mrite a progra to n; te sie o= Output "ormat Sour#e Code 7in#lude8stdio.9 7in#lude8stdlQb.9 Int >#reateArrayint Course/ C 11 m n numbers to Wnd te sum o= e*en numbers in an array. Input "ormat/ Input #onsists o= n1 integers. e =irst integer #orresponds te array. e net n integers #orrespond to te elements in te array. Assume tat te maimum *alue o= n is 15. (e=er sample output =or details. *oid getlementint lnt sumo=ArrayQnt lnt maln: i lnt >a;b.n1 s#ant>?d>;@n:< a6#reateArrayn:< getlementa;n:< b6sumotArraya;n: print=>e sum o= retum O< l lnt Z#reateArrayin N int a< a6int :mallo#nsi retum a< l *oid getlementln i lnt i. =orl6'?d>;ai:< l l int sumo=Arrayint lnt sum6';l< =or%6'08n: ltai:?266': sum6sumai:< l l "[I%T S%III l
Sample input 5 23$+1 Sample Outpu e sum o= te e* (esult us; Program :1 ;int:< Int:< te e*en numbers in te array is/?d>;b:< t n: eotint::< t t a;int n: a.Qnt n: en numbers In te array is/1 > Sum o= *en numbers > as been su##ess=ully ee#uted
Sub0e#t Code/ . Sum o= e*e Mrite a progra #orresponds to *alue o= n is 15 Sour#e Code 7ln#lude8stdlo.9 7in#lude8stdlib.9 Int #reateArrayint *oid getlementin *oid sumo=Arrayln int maln: l int a;n< s#an=>?d;@n:< a6#reateArrayn:< getQementa;n:< sumo=Arraya;n:< retum O< l int #reateArrayin l int a< a6lnt Z:malIo#nsl retum a/ l Course/ C T m XnX ; te sie o= te array. e net XnX integers #orrespond to te elements in te array. Assume tat te maimum :/ t;int:< tZ;lnt:2 n and odd numbers to =ind te sum o= e*en and odd numbers in an array. Input "ormat/ Input #onsists o= n1 integers. e =irst integer Output "ormat/ (e=er sample output =or details.
tn: e'=lnt::< *oid getlementint a;int n: int ii ='lZi6'Ii8liRi: l s#an=>?d>;ai:< l l nt *oid sumo=Arrayi l int i.sum16'.sum2 =ori6'e sum o= print=Ve sum o= l Sample Input 5 23$+1 Sample Outpu :1 i:< t Za.Int n: 6'< te e*en numbers in te array is/B89dn>;sum1:< te odd numbers In te array ls/?dV;sum2:2 e sum o= te e*en numbers in te array is/1 e sum o= te od (esult us; Program d numbers in te array is/2 > Sum o= e*en and odd numbers> as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . Compare 2 arrays Mrite a program to =ind eter 2 arrays are te same. Input "ormat/ Input #onsists o= 2n1 integers. e =irst integer #orresponds to X nX ; te sie o= te array. e net XnX integers #orrespond to te elements in te Wrst array. e net XnX integers #orrespond to te elements in te se#ond array.Assume tat te maimum *alue o= n is 15. Output "ormat/ Print yes i= te 2 arrays are te same. Print no i= te 2 anays are di==erent. Sour#e Code 7Qn#lude8stdl'.9
7ln#lude8stdlQb.9 lnt #reateArrayint:< *oid getlement1 int .int:< *oid getlement2int Z;int:< *oid #e#KArrayint ;int Z;int:< lnt main: t int Za;>b;n< s#an=>?d.@n:< a6#reateArrayn:/ b6#reateArrayn:/ getQement1a;n:< getiement2b.n:< #e#KArray_a;b;n:< retum '< l int >#reateArraylnt n: t lnt at a6int :mallo#nsQeo=lnt::< retum a/ l *oid getlement1 int a;int n: l int i2 ='rl6'2i8n2l: SC$l1>Bod;3l:G l l *oid getlement2int Zb;int n: l int i< =ori6'/i8n/i: i s#an=>?d>.bi:< : l *oid #e#KArrayint Za;int b;Int n: l int I.#6'< =orl6'/i8nai6?dn>.Zai::< BBpQinI=>bi6BodI>.Zbi::< >Zail:66Zbi::: t C< l : i=#66n: = prlnt=>yes>:< Nelse print=>no>:< l l Sample Input
s 23$4 23$4 Sample Output yes (esult us; Program > Compare 2 arrays > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . In*ersion Count Mrite a program to =ind te in*ersion #ount o= an array. In*ersion Count =or an array indi#ates o =ar or #lose: te array is =rom being sorted. i= array is already sorted ten in*ersion #ount is '. I= array is sorted in re*erse order tat in*ersion #ount is te maimum. "ormally speaKing; to elements a_i^ and a_i^ =orm an in*ersion i= a_i^ 9 a_i^ and i 80 ample/ e seYuen#e 2; 4; 1; 3; 5 as tree in*ersions 2; 1:; 4; 1:; 4; 3:. lnput and Output "ormat/ Input #onsists o= n1 integers ere n #orresponds to te number o= elements in te array. e =irst integer #orresponds to n and te net n integers #orrespond to te elements in te array. Output #onsists o= a single integer i# #orresponds to te number o= in*ersions in an array. Assume tat te maimum number o= elements in te array is 2'. (e=er sample input and output =or =ormatting spe#i=i#ations. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdio.9 7ln#lude8stdllb.9 int Z#reateArrayint:< *oid getlementint ;int:< *oid in*ersionCountlnt ;lnt:< int maln: l int Za;n< BBprint=>nter te number o= elements in te arrayn>:< s#an=>B89d>.@n:2 a6#reateArrayn:/ getlementa.n:< ln*ersionCounta.n:< BBprint=>e in*ersion #ount o= te array ls ?dV;b:< retum '< l int Z#reateArrayint n: t int Za< a6lnt :mallo#nsleo=lnt::< retum a/ l *oid getlementint a.int n: t int i/ BBprint=>nter te elements in te arraytn>:< =orl6'?d;ai:/ l l *oid in*erslonCountint a;int n:
l int l;#6';0< =ori6'e in*ersion #ount o= te array lSIBod;C:0 l Sample Input 5 24135 Sample Output e in*ersion #ount o= te array ls/3 (esult us; Program > In*ersion Count> as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . Array Insertion and sorting Mrite a program to insert an element in te array. ample "or eample #onsider an array a*ing tree elements in it initially and a_O^ 6 1; a_1^ 6 2 and a_2^ 6 3 and you ant to insert a number 45 at lo#ation 1 i.e. a_O^ 6 45; so e a*e to mo*e elements one step belo so a=ter insertion a_1^ 6 1 ; and a_2^ 6 2 and a_3^ 6 3. Input and Output "ormat/ Assume tat te maimum number o= elements in te array is 2'. (e=er sample input and output =or =ormatting spe#i=i#ations. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7Qn#lude8stdlo.9 7ln#lude8stdlib.9 int Z#reateArrayint:< *oid getlementint ;int^< *oid insertlonint ;int:< lnt main: i Int n.a< BBprint=>nter te number o= elements in te arrayn>:< s#an=>B89d>.@n:I a6#reateArrayn:/ getlementa.n:< insertiona;n:< retum '/ l lnt #reateArrayint n: l lnt a< a6lnt :malQo#nsleotint::< retum a< l *oid getlementint a.int n: l
Int i/ BBprintt>nter te elements in te arrayn>:< =orl6'?d>.ai:< l l *oid insertlonint a.lnt n: l int Lpos< BBprint=>nter te lo#ation ere you is to insert an elementn>:< s#ant>?d>.@pos:< =orl6n+1I66pOS+1: l IBprint=>nter te *alue to insertn:< s#an=>?d>.ai:< breaK< l l llpos9n: i print1>ln*alid Input:< retum< l print=>Array a=ter insertion isn>:< =orl6'/i8n1?dn> .ai::< : l Sample Input 5 12345 4 1' Sample Output Array a=ter insertion is 1 2 3 %1+Ii+l O (esult us; Program > Array Insertion and sorting> as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . Array Deletion Mrite a program to delete an element =rom te array. input and Output "ormat/ Assume tat te maimum number o= elements in te array is 2'. (e=er sample input and output =or =ormatting spe#i=i#ations. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#iude8stdio.9
7in#lude8stdiQb.9 int #reateArrayint:< *oid getlementint ;int:< *oid deietelementint Z;int:< int maln: i int Za;n< BBprint=>nter te number o= elements in te arrayn>:< s#an=>?d>.@n:< a6#reateArrayn:< getiementa;n:< deleteiementa;n:< retum '< i int #reateArrayint n: l int a< a6int Z:mailo#nsie'=int::< retum a< i *oid getlementint a;int n: l int l/ BBprintt>nter te elements in te arrayn>:< =or%6'8nn: l s#an=>?d.ai:/ l i *oid deletelementint Za.int n: l int i;pos/ BBprint=>nter te lo#ation ere you is to delete an eiementn>:/ s#an=>?d.@pos:< =ori6':< retum< l c prlnt=>Array a=ter deletion ism>:< =ori6'?dn;Zal::/ i c Sample input 5 12345 4 Sample Output
Array a=ter deletion is 1 2 %1'3 (esult us; Program > Array Deletion > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Array \ean Mrite a program to =ind te mean o= te elements in te array. Input and Output "ormat/ lnput #onsists o= n1 integers ere n #orresponds to te number o= elements in te array. e =irst integer #orresponds to n and te net n integers #orrespond to te elements in te array. Output #onsists o= a double *alue i# #orresponds to te mean o= te array. It is printed upto 2 digits o= pre#ision. Assume tat te maimum number o= elements in te array is 2'. (e=er sample input and output =or =ormatting spe#iW#ations All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7Qn#lude8stdlo.9 7in#lude8stdllb.9 int >#reateArrayint:< *oid getlementlnt ;lnt:< *oid array\eanint Z;int:/ lnt maln: lnt a.n< Brprint=>nter te number o= elements in te arrayn>:< s#ant>?d>.@n:< a6#reateArrayn:/ getlementa;n:< array\eana;n:/ retum '/ : Int #reateArrayint n: l lnt a< a6Qnt F:malIo#nsleolint::< retum a< l *oid getlementint a.int n: t Int it BBprintt>nter te elements in te arrayn>:< =ori6'/i8n?d>.ai:< l l *oid anay\eanint Fa;lnt n: l lnt I/ oat add6'.'.add2;mul< =ori6'
l mul6addBn< print=>e mean o= te array is ?.2=>;mul:< l Sample Input 5 24135 Sample Output e mean o= te array ls 3.'' (esult us; Program >Array \ean > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . Array \ean Mrite a program to =ind te mean o= te elements in te array. Input and Output "ormat/ lnput #onsists o= n1 integers ere n #orresponds to te number o= elements in te array. e =irst integer #orresponds to n and te net n integers #orrespond to te elements in te array. Output #onsists o= a double *alue i# #orresponds to te mean o= te array. lt is printed upto 2 digits o= pre#ision. Assume tat te maimum number o= elements in te array is 2'. (e=er sample input and output =or =ormatting spe#i=i#ations All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 7ln#lude8stdlib.9 int Z#reateArrayint:< *oid getlementint ;tnt^< *oid array\eanint V;int:/ lnt main: l Int a;n< BBprint=>nter te number o= elements in te arrayn>:< s#an=>B89d>.@n:I a6#reateArrayn:/ getlementa.n:< array\eana;n:/ retum '/ l lnt #reateArrayint n: l lnt a< a6lnt :mallo#nsleo=int::< retum a< l *oid getlementint a.int n: l Int Q BBprint=>nter te elements in te arrayn>:< =orl6'?d>.ai:< l l *oid array\eanlnt Fa;lnt n: l int l/
oat add6'.'.add2;mul< =ori6'e mean o= te array ls ?.2t>;muQ:< l Sample Input %1''+F`El,,l Sample Output e mean o= te array ls 3.'' (esult us; Program > Array \ean > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Array (ange Mrite a program to =ind te range o= te elements in te array. (ange o= an array is te di==eren#e beteen te maimum and minimum element in an array; input and Output "ormat/ Input #onsists o= n1 integers ere n #orresponds to te number o= elements in te array. e =irst integer #orresponds to n and te net n integers #orrespond to te elements in te array. Output #onsists o= an integer i# #orresponds to te range o= te array. Assume tat te maimum number o= elements in te array is 2'. (e=er sample input and output =or =ormatting spe#i=i#ations. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdto.9 7ln#lude8stdlib.9 int Z#reateArrayint:< *oid getlementint ;int:< *oid array(angeint ;int:< lnt main: l int a;n< BBprint=>nter te number o= elements in te arrayn>:< s#an=>?d.@n:3 a6#reateArrayn:/ getlementa.n:< array(angea;n:< retum '/ l lnt oreateArrayint n: l int >a< a6Qnt :malQo#nsleo=int::< retum a< l *oid getlementint a.int n: l Int I/ BBprint=>nter te elements in te arrayn>:< =ori6'Bd>;ai:<
l l *oid array(angeint a.int n: int l;0;temp6O;d< =ori6'/i8n+1e range o= te array is/?d>.d:< l Sample Input 5 12435 Sample Output e range o= te array ls/4 (esult us; Program > Array (ange> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . \agi# SY A magi# sYu and te num matri is a m rosB#olumn =irst ro =irst; ten se#ond ro and so on. Assume tat te maimum *alue o= m and n is 5. Output "ormat/ Print yes i= it is a magi# sYuare. Prin m Sour#e Cod 7ln#lude8stdlo 7ln#lude8stdllb. Int >#reateArr %3!$ are is an arrangement o= numbers usually integers: in a sYuare grid; ere te numbers in ea# ro; and in ea# #olumn; bers in te =o*ard and ba#Kard main diagonals; all add up to te same number Mrite a program to =ind eter a gi*en agi# sYuare or not. Input "ormat/ e input #onsists o= n>n1: integers. e =irst integer #orresponds to te number o= s in te matri. e remaining integers #orrespond to te elements in te matri. e elements are read in roise order; t no i= it is not a magi# sYuare & 9 9 int: ay ; *oid getleme sint>;lnt:< *oid magi#sYu int maln: i
int a;n< areintF;int:< s#ant>B89d>.@n:< a6#reateArray getlementsa; magl#SYuarea; retum '< l int V#reateArr l int >a;l< a6int>:malQo# =orl6'?d>.a l l l *oid magi#SYu l int l;0;sum6';su sum6'< =orl6'a.lnt n: i:0:I arelnt >a;lnt n: m1 6';r6O;#6'.sum2;sum3;sum4;sum5< 3i:^:< i=sum166sum: r< l sum16sum<
l i=rJ6n+1 $+@ su l print=>n'>:I retum/ l print=>n>:< sum1 6'< =or06'/08n/0: l sum6'< =ori6'sum3 i=#Q6n+1@@sum print=>no>:< retum< l sumt 6'< sum6'< =orl6'/Kn Z ?d sum6'< sum1 6'< =orl6'sum5
B i=sum466sum5 l=sum266sum l print=_>yesn:< l l else print=>non>:< retum< l l Sample lnp 2 45 54 Sample Ou IO (esult us; Progr dn;sum3:< l6': ai:0:< n;sum4:< ai:0:< 89dn>;sum5:< : 3:@@sum366sum4:@@sum266sum4:: ut tput am > \agi# SYuare> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Class TomeorK (ames and Sures ere in te same #lass and got ome orK =rom teir matemati#s tea#er. e TomeorK #onsists o= - strings and ea# string #onsists o= only digits. e tasK i# tey need to per=orm is tat tey need to di*ide te string into 4 integers su# tat teir sum is maimum. -ote/ a# integer sould be 86 1'12 and sould not #ontain any leading eroes. As e Kno tat Sures and (ames are eaK in matemati#s and also tey dont ant to be punised. So; tey need your elp =or =inding te anser. I-P%/ "irst line #ontains an integer - denoting te number o= strings. -et - lines #ontain strings ea# #onsists o= digits only. O%P%/ "or ea# test #ase; Print te reYuired anser it eists. Print >unlu#Ky> oterise. CO-S(AI-S/ 186-861'4 186sie o= ea# string X 2' planationln test #ase 1/4 integers are 4;2;5;1. So maimum sum is 12. In test #ase 2/ 4 integers are 52;3;1;'. So maimum sum is 5. In test #ase 3/ -one o= di*ision ' ; O ; ' ; ': ; ' ; '' ; ' ; : is *alid. S%UASS/ subtasK 1 1 186 -861'2 / 5' pts : subtasK 2 / 186-861'4 / 5' pts: Sour#e Code 7in#lude 8stdio.9 7ln#lude8string.9 #ar s_21^I
long lnt arr_21^_4^< int main: l long int n< BBprlnt=>nter number o= strings/n>:< s#an=>?ld>;@n:< ile n++: N Blprint=>e strings are/n>:< s#ant>B89sn>;s:< long Int len.l.0;K;*al6';#ount6O;/ len6strlens:/ i= len84: N printi>e output isiunlu#Kyin>:< #ontinue< c =or l6'e output isunlu#Kyin>:< else printt>e output ls/?ldn.arr_len+1^_3^:< c
i Sample Input 3 4251 5231 ' '''' Sample Output e output is/12 e output is/5 e output isunlu#Ky (esult us; Program > Class TomeorK > as been su##ess=ully ee#uted
Course/ C X/.Qb^Cl Code . DIA[O-AL \A(I] Diagonal \atri.A sYuare matri i# as eros e*eryere oter tan te main diagonal ntnes on te main diagonal may be any number; in#luding ' Mrite a program to =ind eter a gi*en matri IS a diagonal matri or not Input "ormat e input #onsists o= nn1: integers e =irst integer #orresponds to te number o= rosB#olumns in te matri e remaining mtegers #orrespond to te elements in te matn e elements are read in roise order; =irst ro =irst; ten se#ond ro and so on Assume tat te maimum *alue o= m and n IS 5 Output "ormat Print yes i= it IS a diagonal matn Print no i= it IS not a diagonal matri Sour#e Code 7In#lude8stdlo.9 7in#lude8stdlib.9 int V#reateArrayint: *oid getlementsint> lnt: *oid diagonallementsQnt int: int main: t lnt >a;n< BBprint=>enter te numbero= rosB#olumnsn : s#an=>?d>.@n:/ a6#reateArrayn:/ getlementsa;n:< dlagonallementsa n: retum '/ l lnt >#reateArrayint n: lt i;Va< a6Int>:maQlo#nsieo=Qnt:: =orl6'1i8na Int n: rm l;0< Biprintt>enter te elements o= te matrQn : =orl6'/i8n/l: l
=or06'<^8n<0: i s#an=>?d.Zai:0: l l E l *oid diagonallementsQnt >a Int n: lnt l;0;#6'< =orl6'ai:l::66: l #< l l l l l=#66nZn:+n:: print=>yesn>:/ l else i print=>non>:1 l : Sample Input 2 4 5 5 4 Sample Output T' (esult us; Program > DIA[O-AL \A(I] > as been su##ess=ully ee#uted
#ourse/ C Wm0e#t Code/ . %-I"O(\I \A(I] %ni=ormity matri is a matri in i# all te elements in te matri are eiter #ompletely e*en or #ompletely odd. Mrite a C program to Wnd eter a gi*en matri is a uni=ormity matri or not. Input "ormat/ e input #onsists o= nFn1: integers. e =irst integer #orresponds to te number o= rosB#olumns in te matri. e remaining integers #orrespond to te elements in te matri. e elements are read in roise order; =irst ro =irst; ten se#ond ro and so on. Assume tat te maimum *alue o= m and n is 5. Output "ormat/ Print yes i= it is a uni=ormity matri. Print no i= it is not a uni=ormity matri. Sour#e Code 7ln#lude8stdlo.9 7in#lude8stdlib.9 lnt >Z#reateArrayint:/
*oid getlementsint>;int:< *oid unitormityDQagonalsint>;int:/ lnt main: Int >a;n/ BBprintt>enter te sie o= te matrin>:< s#an=>?d>.@n:/ a6#reateArrayn:/ getlementsa;n:< uni=ormityDiagonaIsa;n:< retum '/ l Int >#reateArrayint n: = lnt>a;I1 a6It>:mallo#nZsieo=intZ::1 =orl6'/i8nenter te elements o= te martrin:< =orl6'/i8n/l: i =or06'<^8n<0: l s#an=>?d.aI:^::< l l l *oid uni=ormityDiagonaQsint a.int n: Int l;0;b6'.#6';d;e< =orl6'i66i: d6Zat:l::< i=d6e:@@dl6':: i print=>non>:< retum< l l l e6d/ l =ori6'
= C< l else t b< l l l >`66>:lQb66>>:: l print=>yesn>:< l else t print=_>non>:< l l Sample Input 2 45 54 Sample Output TO (esult us; Program > %-I"O(\I \A(I]> as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . S\\(IC \A(I] A symmetri# matri is a sYuare matri tat is eYual to its transpose. Mrite a C program to =ind eter a gi*en matri is a sYuare matri or not. input "ormat/ e input #onsists o= mn2: integers. e =irst integer #orresponds to m; te number o= ros in te matri and te se#ond integer #orresponds to n; te number o= #olumns in te matri. e remaining integers #orrespond to te elements in te matri. e elements are read in roise order; =irst ro =irst; ten se#ond ro and so on. Assume tat te maimum *alue o= m and n is 1'. Sour#e Code 7in#lude8stdl'.9 7ln#lude8stdlQb.9 lnt >#reateArrayint;int:< *oid getiementsint>;int.int:< *oid symmetrl#\atriint>;int;int:I lnt maln: l int >a;ros;#olumns< BBprint=>enter te number o= ros and #olumnsn>:< s#an=>?d.@ros:< s#an=>?d>.@#olumns:< a6#reateArrayros.#olumns:/ getlementsa;ros;#olumns:I symmetri#\atra;ros;#olumns:< retum '< l int >#reateArrayint ros;int #olumns: l lnt i;>a<
a6int>:malio#rossieo=int::R =ori6'/Krosa.int ros;int #olumns: Int l;0< IBprint=>enter te elements o= te matrin>:< tori6'?d>.ai:0::/ l l l *oid symmetrl#\atriint >a;int ros;int #olumns: l lnt i;0;#6O< torl6'3i8ros88ai9m66888ani9 l C< l l l i=#66rosZ#olumns:: l prlnt=>Symmetri#nV:/ l else l print=>-ot Symmetri#tn:< l l Sample Input 2 2 1 1 2 2 Sample Output -ot Symmetri# (esult us; Program > S\\(IC \A(I] > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . LOM( (IA-[%LA( \A(I] A loer triangular matri is a sYuare matri in i# all te elements abo*e te diagonal are ero. at is; all te non+ero elements are in te loer triangle/ Mrite a C program to =ind eter a gi*en matri is a loer triangular matri or not. Input "ormat/ e input #onsists
o= n>n1: integers. e Wrst integer #orresponds to te number o= rosB#olumns in te matri. e remaining integers #orrespond to te elements in te matri. e elements are read in roise order; =irst ro =irst; ten se#ond ro and so on. Assume tat te maimum *alue o= m and n is 5. Output "ormat/ Print yes i= it is a loer triangular matri . Print no i= it is not a loer triangular matri. Sour#e Code 7in#lude8stdlo.9 7in#lude8stdlib.9 int >#reateArrayint:< *oid getlementsint>;lnt:< *oid trlangular\atriint>;int:< int main: l lnt >a;n< IBprint=>enter no.o= rosJ#olumnsn>:< s#an=>?d>.@n:/ a6#reateArrayn:/ getlementsa;n:< triangular\atran:< retum O/ l lnt >#reateArrayint n: lnt a;i< a6Int>:mallo#nsieo=int::I =ori6'/i8na;int n: l int L^< Biprintt>enter te elements o= te matrin>:< =orl6'/i8n/l: l =OlZ06OR^8n<0: l s#an=>?d.Zai:0:< l l l *oid triangular\atrilnt>a.int n: l lnt l;0< =or06'<08n<^: l =ori6'-o>:< retum< c
l l print=>es>:< c Sample Input 2 1 2 s 3 Sample Output -o (esult us; Program > LOM( TIA-[%LA( \A(I]> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Art Ce=s ne obby is painting; but e learned te =a#t tat its not easy to paint 2D pi#tures in a ard ay; a=ter asting a lot o= #an*as paper; paint and o= #ourse time. "rom no on; e de#ided to paint 1D pi#tures only. Ce=s #an*as is - millimeters long and is initially all ite. "or simpli#ity; #olors ill be represented by an integer beteen ' and 1'5. ' indi#ates ite. e pi#ture e is en*isioning is also - millimeters long and te it millimeter #onsists purely o= te #olor Ci. %n=ortunately; is brus isnt =ine enoug to paint e*ery millimeter one by one. e brus is 3 millimeters ide and so it #an only paint tree millimeters at a timeit te same #olor. Painting o*er te same pla#e #ompletely repla#es te #olor by te ne one. Also; Ce= as lots o= bottles o= paints o= ea# #olor; so e ill ne*er run out o= paint o= any #olor. Ce= also doesnt ant to ruin te edges o= te #an*as; so e doesnt ant to paint any part beyond te painting. is means; =or eample; Ce= #annot paint 0ust te =irst millimeter o= te #an*as; or 0ust te last to millimeters; et#. Telp Ce= by telling im eter e #an =inis te painting or not it tese restri#tions. Input e =irst line o= te input #ontains an integer denoting te number o= test #ases. e des#ription o= test #ases =ollos. e =irst line o= ea# test #ase #ontains a single integer -. e se#ond line #ontains - spa#e+separated integers C1; C2; ...; CSour#e Code 7ln#lude8stdlo.9 7deWne g get#arunlo#Ked int read: N int n6'< #ar #6g:< ile#8' QQ #9&: `6&:< lle#96' @@ #86&: N n 6 n883: n881: + '< `6&:/ l return n< 1 int main: N lnt t;i;n;ag16O;=lag26';temp.temp1 < t6read:< llet++: N
n6read:< tempt 6'< =ori6'esn>:< else prlnt=>-on>:I tempt 6'< =lag 1 6'< $26'G l return '< l Sample Input 3 4 1555 4 1115 3 552 Sample Output es es -o (esult us; Program > Art> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Serlo#K Tomes ere is a mysterious temple in \ysteryland. e door o= te temple is alays #losed.lt #an only be opened by a uniYue pro#edure.ere are to boes and - items outside te temple.Serlo#K omes *isits te temple many times.a# time Serlo#K olmes *isits te temple;te number o= items - outside te door o= te temple is #anged but ea# time e anyo manages to Kno te #ost o= tose - items.e door o= te temple #an only be opened i= tose >items> are distributed in tose to boes su# tat te sum o= #ost o= items in one bo is eYual to te sum o= #ost o= items in oter bo.Serlo#K omes is trying to do su# a distribution so as to open te door o= te temple.you a*e to tell eter te door te temple #an be opened or not. I-P% te =irst line #ontain te number o= test #ases i.e te number o= time serlo#K omes *isits te temple. -et lines #ontains te des#ription o= tose test #ases."or te =irst line #ontain number o= items >->.e se#ond line #ontains #ost o= tose items. O%P% output >S> i= te door o= te temple
#an be opened oterise output >-O>. Constraint/ 1 86 test#ases 86 1' 1 86 - 86 1'' 1 86 #ost 86 1'' planation tere are tree test#ases test#ase 1/te items #an be distributed in te boes as 4 3 3 4;3;3 ; 5 5 5;5 so output is S test#ase 2/ te items #an be distributed in te boes as 4 1 4;1 3 2 3;2 so output is S test#ase 3/ su# a distribution is not possible. Sour#e Code 7in#lude 8stdio.9 int Doorestlnt ltems_^; int n. int sum: l i= Uase Cases li sum 66 O: return 1< n 66 ' Sum J6 retum '< i= ltems_n+1^ 9 sum: retum Doorestitems; n+1; sum:< return Doorestitems. n+1. sum+items_n+1^: QQ Doorestitems; n+1; sum::< l lnt maln: l lnt no#.test/ BBprint=>nter te number o= test #ases/ n:/ s#an=>?d>;@test:< =orno#6'nter te number o= items/ n>:< s#ant>?d.@n:< BBprinti> nter eigt o= items/ in>:< =ori6'/Kn?d>@items_i^:< totalsum6items_i^2 l it totalsumB892661: prlnt=>-On>:< else i= Doorestitems. n. totalsumB2: 66 1: prlnt=>Sn>:< else prlnt=>-On>:/ c retum '< l Sample Input 3 5 43553 4 1234 2 12 Sample Output S S -O (esult us; Program > Serlo#K Tomes> as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . emperature e daily maimum temperature re#orded in 1' #ities during te mont o= ,anuary =or all 31 days: a*e been tabulated as =ollos/ City 1 2 3 4 5 XXXXXXXXXXX1' Day 1 2 3 . . . . 31 Mrite a program to read te table elements into a to+dimensional array temperature; and to =ind te #ity and day #orresponding to a: te igest temperature b: te loest temperature Sour#e Code 7in#lude8stdio.9 int maln: l int #ityday_5^_5^< int i;0;ma.min;m.n/ m6n61 I prlntt>n>:< tori6'?d.@#ityday_i^_0^:< c ma6#ltyday_'^_'^I =orl6'\a temperature ?d in #ity no ?d on te day ?d>.ma.m;n:/ min6#ltyday_'^_'^< m6rl61 I =ori6'n\in temperature ?d in #ity no ?d on te day ?d>;min;m;n:< retum O< 1 Sample Input so 121 +1 as 31 1' 2 +2 as 33132+234 34123+23 3!15 5+13! Sample Output \a temperature 3! in #ity no 1 on te day 5
\in temperature +2 in #ity no 4 on te day 2 (esult us; Program > emperature> as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C T . Uallots An ele#tion is #ontested by 5 #andidates. e #andidates are numbered 1 to 5 and te *oting is done by marKing te #andidate number on te ballot paper. Mrite a program to read te ballots and #ount te *otes #ast =or ea# #andidate using an array *ariable #ount. In #ase a number read is outside te range 1 to 5 ballot sould be #onsidered as a spoilt ballot and te program sould also #ount te number o= spoilt ballots. Sour#e Code 7ln#lude8stdlo.9 int maln: l Int i.^.K.I.m;n;#ount6';*oter_^6N'c< ^61/K62/l63/m64press 1 to 5 =or *oting/n>:< printt>press ' =or stop *otlng/>:< s#an=>?d;@i:< ilell6': l l=l661: l *oter_1 ^< l6I< c else l=i662: l *oter_2^< K6Q< l else lli663: l *oter_3^< l6Q< l else i=i664: N *oter_4^< m6l< c else lti665: l *oter_5^< n6Q< 1 else l=i95: N #ount< c else l *oter_'^2
i l s#ant>B89d>;@i:< l printt>nCandidate ?d as *otes6?d>.0; *oter_i^:< printt>nCandidate Bod as *otes6?d.K; *oter_K^:< pnnt=>nCandidate ?d as *otes6?d;l; *oter_l^:< print=>nCandldate Bod as *otes6?d.m; *oter_m^:/ print=>nCandidate ?d as *otes6?d>.n; *oter_n^:< print=>nB89d no.'J spoilt *otes>;#ount:< retum O< l Sample Input O-+V7'3'1+I9Cd-fF Sample Output press 1 to 5 tor *oting/ press ' =or stop *otlng/ Candidate 1 as *otes63 Candidate 2 as *otes62 Candidate 3 as *otes61 Candidate 4 as *otes61 Candidate 5 as *otes61 1 n'.o= spollt *otes (esult us; Program > Uallots > as been su##ess=ully ee#uted
#ourse/ C Stib0e#t Code/ . Sele#tion Sorting Sele#tion sort is based on te =olloing idea/ Sele#ting te largest array element and sapping it it te last array element lea*es an unsorted list ose sie is 1 less tan te sie o= te original list. I= e repeat tis step again on te unsorted list e ill a*e an ordered list o= sie 2 and an unordered list sie n+2. Men repeat tis until te sie o= te unsorted list be#omes one ; te result ill be a sorted list. Mrite a program to implement tis algoritm. Sour#e Code 7ln#lude8stdlo.9 lnt maln: l Int A_1O^< int l;K.Small.Lo#< BBprintt>nter lements o= Array/+++n>:< =orl6'?d>.@AW^:< =orK6O
BBprintt>Sorted Array is/nn>:< =ori6'?d >;AW^:< A_K^6Small< BBprint=>Sorted Array is/n>:< =orl6'?d >;A_i^:< retum '< : Sample Input 1' 11 13 1' 12 11 1& 1! 2' 22 Sample Output 1o1o1111121s1!1s2o22 (esult us; Program > Sele#tion Sorting> as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . Uinary Sear# De*elop a program to implement te binary sear# algoritm. is te#niYue #ompares te sear# Key *alue o= te element tat is miday in a soned lies. en < a: I= tey mat#; te sear# is o*er. b: It te sear# Key *alue is less tan te middle *alue; ten te Wrst al= o= list #ontains te Key *alue. #: I= te sear# Key *alue is greater tan te middle *alue; ten te se#ond al= #ontains te Key *alue. (epeat tis di*ide andE#onYuer strategy until e a*e mat#. l= te list is redu#ed to one non+mat#ing element; ten te list does not #ontain te Key *alue. Sour#e Code 7ln#lude8stdlo.9 lnt maln: lnt l;beg;end;mld;a_2'^;ltem< BBprint=>nter 13 elementsn>:/ ='IZi61Ii8613Ri: l s#an=>?d>;@aW^:< l BBprintt>nnter at item you ant to sear#n>:< s#an=>?d>.@item:< bh&61I end613< mid6begend:B2:< llebeg86end @@ a_mld^J6ltem: i ititem8a_mld^: l end6mld+1 / c else
N beg6mid1< l mld6begend:B2:< l ltitem66a_mld^: print=>e Item ls in te llst and its position ls6?d.mid:< else print1>e item ls not in te list>:/ return '/ l Sample Input 1'1112131324!$11'122123 2 Sample Output e item ls ln te list and its position ls6! (esult us; Program > Uinary Sear# > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . -o o= Distin#t elements in a %nsorted array Mrite a program to =ind te number o= distin#t elements in a unsorted array. _Do it itout sorting te array^ Input "ormat/ Input #onsists o= n1 integers. e =irst integer #orresponds to n; te number o= elements in te array. e net n integers #orrespond to te elements in te array. Assume tat te maimum *alue o= n is 15. Output "ormat/ Output #onsists o= a single integer i# #orresponds to te number o= distin#t elements in te array. Sour#e Code 7ln#lude8stdio.9 7in#Iude8stdlIb.9 int #reateArrayint:< *oid readlementint ;int:< *oid distin#tlementint Z;int:/ int main: t int a;n< s#an=>B89d>.@n:/ a6#reateArrayn:I readlementa.n:< distln#tIementa.n:< retum '< I Int #reateArrayint n: t int Za< a6int Z:malIo#nsie'tint::< retum a/ I *oid readlementint a;int n: Int I/ =ori6'/i8n/I: I s#an=>?d>.ai:/ I I
*oid distin#tQementint Za.int n: I Int l;0;b61;d6'< tori6'B9d;d:< I Sample Input 5 323!$'&' Sample Output 4 (esult us; Program > -o o= Distin#t elements in a %nsorted array> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Sum o= positi*e -umbers Mrite a program to =ind te sum o= positi*e numbers in an array. Input "ormat/ Input #onsists o= n1 integers. e =irst integer #orresponds to XnX ; te sie o= te array. e net XnX integers #orrespond to te elements in te array. Assume tat te maimum *alue o= n is 15. Output "ormat/ (e=er sample output =or details. Sour#e Code 7ln#lude8stdlo.9 7ln#lude8stdllb.9 Int #reateArrayint:/ *oid readlementlnt ;int:< int sumo=Arraylnt .lnt:< int maln: l lnt a;b.nI s#an=>?d.@n:l a6#reateArrayn:< readlementa;n:< b6sumo=Arraya;n:< print=>e sum o= te positi*e numbers in te array ls/B9d>;b:< retum '< l int #reateArrayint n: l lnt a< a6int :mallo#nsieo=lnt::< retum a< l *oid readQementlnt a;int n:
t lnt i/ =orl6'?d>;ai:< l i int sumo=Arrayint a.Qnt n: lnt i;sum6'< =orl6'?dV.sum:< retum sum< : Sample Input 5 23$+1 Sample Output e sum o= te positi*e numbers in te array is/1& (esult us; Program > Sum o= positi*e -umbers> as been su##ess=ully ee#uted
. Alpabeti#al Order Mrite a progra [I-(S. Sour#e Code 7in#lude8stdIo.9 7ln#lude8strIng.9 lnt maln: #ar a_3'^;temp2 Int n6';0;i< print=>nnter te s#an=>?s>;a:< ilea_n^l6O: n< l =ori6'161_i1966_i1^: i temp6a_< a_^^6a_01^I a_Q1^6temp< l l l print=>ne string
=ori6'/i8n?#;a_i^:< l retum '/ l Sample Input string Sample Outpu nter te string/ e string ln alp abet (esult us; Program #ourse/ C =pb0e#t Code/ m i# ill read a string and rerite it in te alpabeti#al order. "or eample; te ord S(I-[ sould be ritten as strlng/>:l in alpabeti#al order is/>:< t i#al order is/glnrst > Alpabeti#al Order> as been su##ess=ully ee#uted
#ourse/ C X/.lb^eC Code/ . ASCII -ame Mrite a program i# reads your name =rom te Keyboard and output a list o= A-CII #odes; i# represent your name Sour#e Code 7in#lude8stdio.9 7ln#lude8string.9 int main: t int K;i;Q/ #ar _1''^< print=>nter a S"tl-[/n:/ s#an=>?s>;:< l6strQen:< print=>e ASCII *alues o= te string are/n>:< =ori6'?d >;K:< l retum O< c Sample Input S(\%-I)(SI Sample Output nter a S(I-[/ e ASCII *alues o= te strlng are/ $3 $2 !! $5 !$ !3 $ & $2 $3 !3 $4 $& (esult us; Program > ASCII -ame > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . Cara#ter tra#t Mrite a program to etra#t a portion o= a #ara#ter string and print te etra#ted string. Assume tat m #ara#ters are etra#ted; starting it te nt #ara#ter. Sour#e Code 7in#lude8stdlo.9 7dene \A] 5' int maQn: t #ar Str1_\A]^/ int i;m.n.^< print=Vnter A String>:< s#an=>?s>;Str1 :< printt>nnter -umber o= Cara#ters Mi# ou Mant to tra#t>:< s#ant>?d>.@m:/ printt>nnter Ueginning Inde =rom i# ou Mant to tra#tt>:< s#an=>?d>;@n:< print=>ntra#ted String is/>:< tori6n+1BoC.H%1_i^:G l retum O< l Sample Input S(\%ni*ersityLearnlngCentre 1' 5 Sample Output nter A String/ nter -umber o= Cara#ters Mi# ou Mant to tra#t/ nter Ueginning Inde =rom Mi# ou Mant to tra#t/ tra#ted String is/ni*ersityL (esult us; Program >Cara#ter tra#t > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Conse#uti*e String Copy Mrite a program tat ill #opy m #onse#uti*e #ara#ters =rom a string s1 beginning at position n into anoter string s2 Sour#e Code 7in#Iude8stdio.9 7de=ine \A] 5' int main: l #ar Str1_\A]^;Str2_\A]^< int i;m;n;0< print=>nnter A Strlng>:< soant>?s>;Str1 :< print=>nnter -umber o= Cara#ters Mi# ou Mant to Copyi>:/ s#ant>?d>.@m:/ printt>nnter Ueginning Inde =rom Mi# ou Mant to Copy/>:/ s#ant>?d;@n:< torl6n+1;06'
l Str2_m^6'< printt>nCopied String iSIBoH>.Stt2:< return '< l Sample Input S(\%nI*erslty 5 1 Sample Output nter A String/ nter -umber o= Cara#ters Mi# ou Mant to Copy/ nter Ueginning Inde =rom Mi# ou Mant to Copy/ Copied String is/S(\%n (esult us; Program > Conse#uti*e String Copy > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Con*ersion Code +'1 Mrite a C program to #on*ert loer#ase string to upper#ase string using inbuilt string library =un#tion strupr:internally #ara#ters in C are represented as an integer *alue Knon as ASCII *alue. Mi# means i= e rite A or any oter #ara#ter it is translated into a numeri# *alue in our #ase it is 5 as ASCII *alue o= A 6 &!. Tere at e need to do is =irst e need to #e#K eter te gi*en #ara#ter is loer#ase alpabet or not. It it is loer#ase alpabet 0ust subtra#t 32 =rom it i# ill result in upper#ase alpabet Sin#e ASCII *alue o= A65; a6&! teir diWeren#e is &!+5 6 32:. Sour#e Code 7in#lude8stdlo.9 7detlne \A]SIR 1'' BB\almum sie o= te string lnt maln: l #ar strlng_\A]SlR^< int i< IZ (eads a string =rom user B print=>nnter your teti>:< s#an=>?s>;strlng:< tori6'< strlng_l^l6Z'< i: l B. I= #urrent #ara#ter is loer#ase alpabet ten #on*ert lt to upper#ase. 1 i=string_i^96a @@ string_i^86: string_i^ 6 string_i^+32< l l printt>n%pper#ase string/B89s>;string:< return '< l Sample Input srmunl*ersity Sample Output nter your tet/ %pper#ase strlng/S"t\%-l)"tSl
(esult us; Program > Con*ersion Code +O1 > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . Con*ersion Code +'2 Mrite a C program to #on*ert upper#ase string to loer#ase using inbuilt string library =un#tion strlr:. To to use strlr library =un#tion in C programming. Internally #ara#ters in C are represented as an integer *alue Knon as ASCII *alue. Mi# means i= e rite a or any oter #ara#ter it is translated into a numeri# *alue in our #ase it is &! as ASCII *alue o= a 6 &!. Tere at e need to do is =irst e need to #e#K eter te gi*en #ara#ter is upper #ase alpabet or not. I= it is upper#ase alpabet 0ust add 32 to it i# ill result in loer#ase alpabet Sin#e ASCII *alue o= A65; a6&! teir di==eren#e is &!+5 6 32:. Sour#e Code 7ln#lude 8stdio.9 7de=lne \A]SlR 1'' BB\aimum sie o= te string Int maQn: I #ar string_\A]SlR^< Int i< B (eads string =rom user B print=>n nter any string>:< s#an=V?s> ;strl ng:< BB(uns a loop tlll last #ara#ter o= string t'ri6'< strlng_l^l6'< I: I i=strlng_l^96A @@ strlng_l^86R: I string_i^ 6 string_i^ 32< I 1 print=VnLoer #ase string/?s>; string:< return '< I Sample Input S(\%-I)(SILA(-I-[C-( Sample Output nter any string/ Loer #ase string/srmunI*ersitylearning#entre (esult us; Program >Con*ersion Code +'2 > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Copy Count Mrite a C program to #opy one string to anoter string using loop. C program to #opy one string to anoter itout using inbuilt library =un#tion str#py: and #ount total number o= #ara#ters #opied. To to #opy one string to anoter and #ount total #ara#ters #opied it and itout using inbuilt string library =un#tion Sour#e Code 7in#lude 8stdio.9 int maln:
#ar tet1_1''^. tet2_1''^< int i< printt>nter any string/ >:< s#an=>?s>;tet1 :3 B Copies tett to tet2 #ara#ter by #ara#ter B 6'< QQetet1_l^l6': N tet2_i^ 6 tetl _i^< i< c BB\aKes sure tat te string is -%LL terminated tet2_i^ 6 '< print=>n"lrst strlng6?s>;tet1:I printt>nSe#ond string6?s>;tet2:/ printt>notal #ara#ters #opied6?d>; I:< return '< i Sample Input S(\%ni*ersity Sample Output nter any string/ I>+llZS1 strQng6S"t\%ni*ersQty Se#ond string6S(\%nl*ersity otal #ara#ters #opied613 (esult us; Program > Copy Count > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . Count a String Mrite a C program to #ount total n Sour#e Code 7in#lude 8stdio.9 umber o= alpabets; digits or spe#ial #ara#ters in a string using loop To to =ind total number o= alpabets; digits and spe#ial #ara#ters in a string in C programming 7detlne \A]SlR 1'' BB\almum sie o= te string lnt main: l #ar string_\A]SlR^< int alpabets. digits. oters; I< alpabets 6 digits 6 oters 6 i 6 '< IZ (eads a strlng =rom user B print=>nter any string/>:< s#an=>?sV;string:/ _ Ce#Ks ea# #ara#ter o= string B llestrlng_i^l6': N i=strlng_l^96a @@ strlng_l^86: N alpabets< c else l=string_i^96' @@ strlng_l^86&: l digits<
l else N oters< c iR l printtnAlpabets6?d>; alpabets:< print=>nDlgits6?d>; digits:< print=>nSpe#ial #ara#ters6?d>; oters return '/ l Sample Input S(\J%ni*ersltyhLeaming@Centreh1 1 13 Sample Output nter any string/ Alpabets62! Dlglts64 Spe#ial #ara#ters64 (esult us; Program > Count a String > QQ strlng_l^96A @@ strlng_i^86R:: l< as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . "reYuen#y o= ea# Mrite a C program to #ount =reYuen#y o= ea# #ara#ter in a string using loop Sour#e Code 7In#Qude 8stdio.9 7In#lude 8string.9 7de=Qne \A]SlR 1'' BB\aimum sie o= te string Int main: I #ar string_\A]SQR^< Int i; Ien< Int =reYuen#y_2^< B (eads a string =rom user I print=>nter any string/ >:< s#an=>?s>;strlng:< len 6 stilenstrlng:< BZ Initialies =reYuen#y o= ea# #ara#ter to ' B tori6'/ i82/ i: I =reYuen#y_Y 6 '3 c BF "inds total number o= o##urren#es o= ea# #ara#ter B ='Ii6'< i8len< i: I B I= te #urrent #ara#ter is loer#ase alpabet B itstrlng_l^96a @@ string_i^86: t =reYuen#y_string_i^ + &!^< I else I=string_l^96A @@ string_Y86R: I =reYuen#y_strlng_l^ + 5^<
I c B Z Prints te =reYuen#y o= all #ara#ters In te string I print=>n"reYuen#y o= all #ara#ters in te gi*en string/ n>:/ =ori6'< i82< i: I IZ I= te #urrent #ara#ter is In gi*en string I i==reYuen#y_i^l6': t print=>?# 6 ?dn>. i&!:; =reYuen#y_i^:< I I return '/ I Sample Input smmnl*ersitylearntng#entre Sample Output nter any string/ "reYuen#y o= all #ara#ters In te gi*en string/ a 6 1 6 1 88C>Z\>/3>`DO ...Q!Q9+l9<< .;<< 63 61 (esult us; Program > "reYuen#y o= ea# > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . \aimum "reYuen#y To to =ind igest =reYuen#y #ara#ter in a string using loop in C programming."ind =reYuen#y o= ea# #ara#ters in te string and store it in some array o= integers. "ind maimum element in te array. \aimum element in te array ill te be maimum o##urring #ara#ter in te string. Sour#e Code 7ln#lude 8stdio.9 7de=lne \A]SlR 1'' BB\aimum sie o= te string 7de=ine \A]CTA(S 255 BB\aimum #ara#ters alloed lnt maln: t #ar string_\A]SlR^< int =reYuen#y_\A]CTA(S^/ BBStores =reYuen#y o= ea# #ara#ter int i 6 '; ma< int as#ii< print=>nter any string/ >:< s#an=?s>;strlng:< BZ Initialies =reYuen#y o= all #ara#ters to ' I =ori6'I i8\A]CTA(S< i: N =reYuen#y_Q^ 6 '/ : B "inds =reYuen#y o= ea# #ara#ters B i6'< llestring_i^ l6 ':
N as#li 6 int:strIng_l^< =reYuen#y_as#ii^ 6 1< i2 c BZ "inds maimum =reYuen#y B ma 6 O2 ='Qi6'< i8\A]CTA(Sl Q: N i==reYuen#y_i^ 9 =reYuen#y_ma^: ma 6 i< c print=>nTigest =reYuen#y o= B'C is BOd n>; ma; =reYuen#y_ma^:< return '/ l Sample Input srmunl*ersity Sample Output nter any string/ Tigest =reYuen#y o= i is 2 (esult us; Program >\aimum "reYuen#y > as been su##ess=ully ee#uted
Course/ C Syb0e#t Code/ . \inimum "reYuen#y To to =ind loest =reYuen#y #ara#ter in a string using loop in C programming Sour#e Code 7in#lude 8stdio.n9 7de=ine \A]SlR 1'' BB\aimum sie o= te string ==de=lne \A]CTA(S 255 BB\aimum #ara#ters alloed int maln: l #ar string_\A]SlR^< int =reYuen#y_\A]CTA(S^< B1Stores =reYuen#y o= ea# #ara#ter lnt i 6 O; min/ Int as#ii< print=>nnter any string/>:< s#an=>?s>.string:< B Initialies =reYuen#y o= all #ara#ters to ' r =ori6'< i8\A]CTA(S/ l: N =reYuen#y_Q^ 6 '/ c B "inds =reYuen#y o= ea# #ara#ters B i6'< llestring_i^ J6 ': N as#li 6 int:string_l^/ =reYuen#y_as#iY 6 1< i< l B "inds minimum =reYuen#y I mln 6 '< =ori6'< i8\A]CTA(S< I: N i==reYuen#y_l^ l6 O: i
i==reYuen#y_min^ 66 ' QQ =reYuen#y_i^ 8 =reYuen#y_min^: min 6 I< l i print=>nLoest =reYuen#y o= B'C is ?d>; min; =reYuen#y_min^:< return '< i Sample Input madam Sample Output nter any string/ Loest =reYuen#y o= d is 1 (esult us; Program > \inimum "reYuen#y > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . (emo*e All o##urren#e C program to remo*e all o##urren#es o= a #ara#ter =rom te string Sour#e Code 7ln#lude 8stdio.9 7ln#lude 8string.9 7de=lne \A]SlR 1'' BB\aimum sie o= te string 1>Z "un#tion de#laration B *oid remo*eAQl#ar ; #onst #ar:/ int maln: t #ar string_\A]SlR^< #ar to"temo*e< printt>n nter #ara#ter to remo*e =rom string/:< to"temo*e 6 get#ar:< print=>nnter any string />:< s#an=>B9s>;string:< remo*eAllstrlng; t'(emo*e:/ printt>nStnng a=ter remo*ing ?#/B9s;to(emo*e; stnng:< return '2 l _)' "un#tion to remo*e all o##urren#es o= a #ara#ter =rom te string. B *oid remo*eAll#ar Z string; #onst #ar to(emo*e: Int l; 0< lnt len 6 strlenstring:< tori6'< i8len< i: N BI Z I= te #ara#ter to remo*e is =ound ten si=t all #ara#ters to one Z pla#e le=t and de#rement te lengt o= string by 1. B i=string_l^ 66 to(emo*e: t ior06l< ^8len+1< 0: l strlng_0^ 6 stringl0+1^< : len++< string_len^ 6 '<
B1 It a #ara#ter is remo*ed ten maKe sure I doesnt in#rements I++< l 1 l Sample Input $ madam Sample Output nter #ara#ter to remo*e =rom string/ nter any string/ String a=ter remo*ing amdm (esult us; Program > (emo*e All o##urren#e> as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . (emo*e Inde String 1 Mrite a =un#tion to remo*e =irst o##urren#e o= a ord =rom te string. Sour#e Code 7in#lude 8stdio.9 7in#lude 8string.9 ==dene \A]SlR 1'' I> "un#tion de#laration I *oid remo*e"irst#ar Z tet; #onst #ar to(emo*e:< int main: l #ar tet_\A]SiR^< #ar to(emo*e_\A]SIR^/ B (eads a string =rom user and #ara#ter to be sear#ed I printt>nter any string/>:I s#an=>?sV;tet:< print=>nnter string to be remo*ed>:< s#an=?s>;to(emo*e:< remo*e"irsttet. to(emo*e:< print=>n"inai string a=ter remo*ing ?s 6 B'3. to(emo*e. tet:< return '< t _I1' (emo*es te =irst o##urren#e o= a string in anoter string I *oid remo*e"irst#ar Z tet. #onst #ar to(emo*e: i int i; 0< int len; remo*eLen< int =ound 6 '< Ien 6 strientet:< remo*eLen 6 strlento(emo*e:/ =ori6O< i8ien< i: N =ound 6 1< =or06'/ i8remo*eLen< 0: N i=tet_i0^ l6 to(emo*e_0^: i =ound 6 '<
breaK< i i B. i= ord as been =ound ten remo*e it by sitting #ara#ters rigt to it to le=t. B it=ound 66 1: i =or^6i< 08len+remo*eLen< 0: i tet^ 6 tet remo*eLen^< i tet_0^ 6 '/ breaK< c c i Sample Input S(\%-I)(SI S(\ Sample Output nter any string/ nter string to be remo*ed/ Tnal string a=ter remo*ing S(\ 6 %-I)(SI (esult us; Program > (emo*e Inde String 1 > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . (emo*e Inde String 2 Mrite a C program to remo*e =rom last o##urren#e o= a ord in gi*en string using loop Sour#e Code 7ln#lude 8stdio.9 7ln#Iude 8string.9 7de=ine \A]SlR 1'' BB\aimum sie o= string int maln: i #ar string_\A]SlR^< #ar ord_\A]SIR^< lnt i; 1; =ound. inde< lnt strlngLen. ordLen< It > (eads string and ord =rom user F1 print=>nter any string/:< s#an=>B9s>.string:I print=>mnter any ord to sear#=:/ s#an=B9s>.ord:< stringLen 6 strlenstring:< BB"inds lengt o= string 'rdLen 6 strlenord:< BB"inds lengt o= ord Bt (uns a loop =rom starllng inde o= string to V lengt o= string + ord lengt I inde 6 +1< =orl6'< i8stringLen + ordLen< l: N
BB\at#es te ord at #urrent position =ound 6 1< =or^6'< 08ordLen/ 0: N BBI= ord ls not mat#ed itstring_l0^ l6 ord_: N =ound 6 '< breaK< l l BBI= ord a*e been =ound ten store te #urrent =ound lnde i==ound 66 1: t lllde] 6 l l BBi= MOld I1'1 =ound l=lnde 66 +1: N prlnt=>n?s not =ound>;string:< c else N _' Z Si=ts all #ara#ters =rom rigt to le=t F1 =orl6inde< i8stringLen + 'rdLen< l: N string_i^ 6 strlng_i ordLen^< c BB\aKes last #ara#ter null. string_i^ 6 '/ prlnt=>nStrlng a=ter remo*ing last ?s/?s>; ord; string:< l return '/ l Sample Input lLo*eCProgramming Lo*e Sample Output nter any string/ nter any ord to sear#/ String a=ter remo*lng last Lo*e/lCProgrammlng (esult us; Program > (emo*e Inde String 2V as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . (emo*e Inde String 3 Mrite a C program to remo*e all o##urren#es o= a gi*en ord in string using loop Sour#e Code 7ln#lude 8stdio.9 7in#Iude 8string.9 7detine \A]SlR 1'' BB\aimum sie o= string B "un#tion de#laration 1 *oid remo*eAli#ar > string; #ar to(emo*e:< lnt main:
l #ar string_\A]SlR^< #ar to(emo*e_\A]SIR^/ B (eads string and ord =rom user I printt>nter any string/ >:< s#an=>?s>;strlng:< printt>nnter ord to remo*e/ >:< s#an=?s>;to(emo*e:< printi>nString be=ore remo*ing ?s /?s>; to(emo*e; string:< remo*eAllstring; t'(emo*e:/ printi>nStnng a=ter remo*ing ?s /?s>; to(emo*e; string:< return '2 l _IO (emo*es all o##urren#es o= a gi*en ord in string. B *oid remo*eAll#ar Z string; #ar Z to(emo*e: l int l; 0; stringLen; to(emo*eLen< int =ound< stringLen 6 strlenstring:/ BB[ets lengt o= string to(emo*eLen 6 striento(emo*e:< BB[ets lengt o= ord to remo*e =ori6'< i8stringLen + to"temo*eLen< i: l B. \at#es ord it te string 1 =ound 6 1< tor06'< 08to(emo*eLen< 0: l i=string_i 0^ l6 to(emo*e_0^: l tound 6 '< breaK< 1 l It Z I= ord is =ound ten si=t all #ara#ters to Iett and de#rement te string lengt B i==ound 66 1: i ='r06i< i8stringLen + to(emo*eLen< 0: N strlng_0^ 6 string_0 to(emo*eLen^< l string^ 6 O< stringLen 6 stringLen + to(emo*eLen< c i l Sample Input S(\%-I)(SIS(\%-I)TSI S(\ Sample Output nter any string/ nter ord to remo*e/
String be=ore remo*ing S(\ / S(\%-I)(SIS(\%-I)(SI String a=ter remo*ing S(\ / %-I)(SI%-I)(SI (esult us; Program >(emo*e Inde String 3 > as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C 11 . (emo*e Last o##urren#e Mrite a C program to read any string =rom user and remo*e te last o##urren#e o= a gi*en #ara#ter =rom te string Sour#e Code 7in#lude 8stdio.9 7ln#lude 8strtng.9 7dellne \A]SlR 1'' BB\aimum sie o= te string 1>Z "un#tion de#laration B *oid remo*eLast#ar Z. #onst #ar:/ int main: #ar string_\A]SlR^< #ar to(emo*e< print=>nter #ara#ter to remo*e =rom string>:< to(emo*e 6 get#ar:< printt>n nter any string 1>:< s#an=B9s>;strlng:< remo*eLaststrQng; to(emo*e:< printt>nOutput/?s>.string:< return '/ l PO "un#tion to remo*e last o##urren#e o= a #ara#ter =rom te string. B *oid remo*eLast#ar string; #onst #ar to(emo*e: Int I; Q3SlPOSQtiOllG int len 6 strlenstring:/ lastPosltion 6 +1< llei8len: N i=strlng_l^ 66 to(emo*e: l lastPositlon 6 I< c i< I i=lastPosition l6 +1: N i 6 IastPosltion< In > Si=t all #ara#ters rigt to te position tound abo*e to le=t r ileKQen+1: l string_i^ 6 string_i1^< i< c l
B \aKe te last #ara#ter null ZB strlng_i^ 6 '< l Sample Input 3 madam Sample Output nter #ara#ter to remo*e =rom string/ nter any string/ Output/madm (esult us; Program > (emo*e Last o##urren#e > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . (emo*e (epeated Cara#ters in a String Mrite a C program to remo*e all repeated #ara#ters in a string using loops Sour#e Code 7in#lude 8stdio.9 7detine \A]SlR 1'' BB\aimum sie o= te string B "un#tion de#larations I *oid remo*eDupli#ates#ar string:< *oid remo*eAll#ar > string; #onst #ar to(emo*e; int inde:< int main: l #ar string_\A]SQR^< B (eads string =rom user B printt>n nter any string 1>:< s#an=B9s>.string:/ print=>nString be=ore remo*ing dupli#ates/?s>; string:/ remo*eDupll#atesstring:< print=>nString a=ter remo*ing dupli#ates/?s>; string:< return '< l ;.. (emo*es all dupli#ate #ara#ters =rom te gi*en string B *oid remo*eDupli#ates#ar string: l int l 6 O< lQestring_i^ J6 ': N BZ (emo*e all dupli#ate o= #ara#ter string_i^ B remo*eAlIstring; strlng_l^; i:< lR c l B.. (emo*es all o##urren#es o= a gi*en #ara#ter =rom string a=ter te gi*en Inde. B *oid remo*eAQl#ar Z string; #onst #ar to(em'*e; int inde: l Int l; 0< i 6 Inde 12 llestrlng_i^ i6 ': N BZ It dupli#ate #ara#ter is =ound >B
i=string_l^ 66 to(emo*e: l =Z Si=t all #ara#ters =rom #urrent position to one pla#e Ieit .Z. l ilestring_Q^ l6 ': N strlng_^^ 6 string_0 1^< 0< c c l< c l Sample Input smuni*ersity Sample Output nter any string/ String be=ore remo*ing dupll#atessrmuni*ersity String a=ter remo*ing dupli#ates/srmuni*ety (esult us; Program > (emo*e (epeated Cara#ters in a String> as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . (emo*e Inde String 1 Mrite a =un#tion to remo*e =irst o##urren#e o= a ord =rom te string. Sour#e Code 7in#lude 8stdio.9 7in#lude 8string.9 ==dene \A]SlR 1'' I> "un#tion de#laration I *oid remo*e"irst#ar Z tet; #onst #ar to(emo*e:< int main: l #ar tet_\A]SiR^< #ar to(emo*e_\A]SIR^/ B (eads a string =rom user and #ara#ter to be sear#ed I printt>nter any string/>:I s#an=>?sV;tet:< print=>nnter string to be remo*ed>:< s#an=?s>;to(emo*e:< remo*e"irsttet. to(emo*e:< print=>n"inai string a=ter remo*ing ?s 6 B'3. to(emo*e. tet:< return '< t _I1' (emo*es te =irst o##urren#e o= a string in anoter string I *oid remo*e"irst#ar Z tet. #onst #ar to(emo*e: i int i; 0< int len; remo*eLen< int =ound 6 '<
Ien 6 strientet:< remo*eLen 6 strlento(emo*e:/ =ori6O< i8ien< i: N =ound 6 1< =or06'/ i8remo*eLen< 0: N i=tet_i0^ l6 to(emo*e_0^: i =ound 6 '< breaK< i i B. i= ord as been =ound ten remo*e it by sitting #ara#ters rigt to it to le=t. B it=ound 66 1: i =or^6i< 08len+remo*eLen< 0: i tet^ 6 tet remo*eLen^< i tet_0^ 6 '/ breaK< c c i Sample Input S(\%-I)(SI S(\ Sample Output nter any string/ nter string to be remo*ed/ Tnal string a=ter remo*ing S(\ 6 %-I)(SI (esult us; Program > (emo*e Inde String 1 > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . (emo*e String 1st O##urren#e Mrite a C program to read any string =rom user and remo*e =irst o##urren#e o= a gi*en #ara#ter =rom te string Sour#e Code 7ln#lude 8stdio.9 7ln#lude 8string.9 7de=lne \A]SlR 1'' BB\aimum sie o= te string B> "un#tion de#laration I *oid remo*e"irst#ar F; #onst #ar:< rm main: l #ar string_\A]SlR^< #ar to(emo*e< print=>nnter #ara#ter to remo*e =rom string/ >:/ to(emo*e 6 get#ar:/ print=>nnter any string/ >:/ s#an=>?s>;string:< remo*e"irststring; to(emo*e:/ print=>nOutput/B89s>. string:<
return '< i ;.. "un#tion to remo*e Wrst o##urren#e o= a #ara#ter =rom te string. B *oid remo*e"lrst#ar > string; #onst #ar to(emo*e: t lnt i< int len 6 strlenstrlng:< 6'< BZ (un loop until te Wrst o##urren#e o= te #ara#ter is not =ound ZB lieKlen @@ stringW^l6to(emo*e: i< BI Si=t all #ara#ters rigt to te posltlon =ound abo*e to one pla#e le=t 1 lleKlen+1: N strlng_i^ 6 stnng1^/ i< c BF \aKe te last #ara#ter null 1 string_i^ 6 '/ : Sample Input l srmunl*ersitylearning#entre Sample Output nter #ara#ter to remo*e =rom string/ nter any string/ Output/srmun*ersltyleaming#entre (esult us; Program > (emo*e String 1st O##urren#e> as been su##ess=ully ee#uted
Course/ C Stib0e#t Code/ . (epla#e 1st O##urren#e o= String To to repla#e =irst o##urren#e o= a #ara#ter it anoter #ara#ter in a string using loop in C programming Sour#e Code 7in#lude 8stdio.9 7de=ine \A]SQR 1'' Br\aimum sie o= te string B "un#tion de#laration B *oid repla#e"Qrst#ar string; #ar to(epla#e. #ar repla#eit:< int main: l #ar string_\A]SlR^; to(epla#e; repla#elt/ print=>nter any string:< s#an=V?s>;string:< print=>nter #ara#ter to repla#e/>:< s#an= ?#>. @to(epla#e:< print=>nter #ara#ter to repla#e ?# it>; to(epla#e:< s#an= B''>; @repla#eMit:< print=>nString be=ore repla#ing/?s>; string:< repla#e"irststrlng. to(epla#e; repla#elt:/ print=>nStnng alter repla#ingXBus>; string:< return '< l
PI (epla#es te =irst o##urren#e o= a #ara#ter it anoter in gi*en string. B *oid repla#e"irst#ar Z string; #ar to(epla#e; #ar repla#elt: l int i6'/ B> (uns till te end o= string ZB ilestring_i^ l6 ': N BZ I= an o##urren#e o= #ara#ter is =ound 1 i=string_l^ 66 to(epla#e: l string_i^ 6 repla#e*lWt< breaK/ l i< i l Sample Input arm $ S Sample Output nter any string/nter #ara#ter to repla#e/nter #ara#ter to repla#e a it/ String be=ore repla#ingarm String a=ter repia#lng/srm (esult us; Program > (epla#e 1st O##urren#e o= String> as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C 11 . (epla#e a string Mrite a C program to repla#e all o##urren#e o= a #ara#ter it anoter in a string using =un#tion Sour#e Code 7in#lude 8stdio.9 7de=ine \A]SlR 1'' BB\aimum sie o= te string BZ "un#tion de#laration B *oid repla#e#ar Z string. #ar to(epla#e. #ar repla#eMit:< lnt main: l #ar string_\A]SlR^; to(epla#e; repla#elt/ print=>nter any string/>:< s#an=>?s>;string:1 print=Vnter #ara#ter to repla#e/>:/ s#ant ?#>. @to(epla#e:< print=>nter #ara#ter to repla#e ?# lt/>; to(epQa#e:/ s#an=> ?#>; @repla#eMit:< print=>nString be=ore repla#ing/?s>; string:< repla#estring; to(epla#e; repla#elt:< print=>nString a=ter repla#ing/ ?s>; string:< return '/ l PO (epla#es te all o##urren#e o= a #ara#ter it anoter in gi*en string.
I *oid repla#e#ar Z string; #ar to(epla#e; #ar repla#elt: l int i 6 O< BZ (uns tlll te end o= string B llestring_i^ l6 e>: N IZ I= an o##urren#e o= #ara#ter is =ound >B i=strlng_Q^ 66 to(epla#e: i string_i^ 6 repla#e)lWt< c i< I l Sample Input S=3S=3H$ $ m Sample Output nter any string/nter #ara#ter to repla#e/nter #ara#ter to repla#e a it/ String be=ore repla#lngsrasrasra String a=ter repla#ing/ smlsrmsrm (esult us; Program > (epla#e a string > as been su##ess=ully ee#uted
#ourse/ C Sub0e#t Code/ . ASCII -ame Mrite a program i# reads your name =rom te Keyboard and output a list o= A-CII #odes; i# represent your name Sour#e Code 7in#Iude8stdio9 7ln#Iude8string.9 Int main: l int K;i;l< #ar _1''^< BBprintt>nter a S(l-[/>:< s#an=>?s>;:< l6strlen:< print=>ne ASCII *alues oi te string are+n>:< tori6'Bod >;:< I retum '< c Sample Input S(\%-I)(SI Sample Output e ASCII *alues o= te string are/ $3 $2 !! $5 !$ !3 $ & $2 $3 !3 $4 $& (esult us; Program > ASCII -ame > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . In*entor C Mrite a program to do te =olloing/ a: o output te Yuestion XMo is te in*entor o= CXX. b: o a##ept an anser. #: o print out X [oodX and ten stop; i= te anser is #orre#t. o output te message Xtry againX it te anser is rong. d:o display te #orre#t anser en te anser is rong e*en at te tird attempt and stop. Sour#e Code 7in#lude8stdlo.9 lnt maln: #ar s1 _25^< #ar s2_25^6>Dennis(it#ie< int n< IBprintt>Mo is te in*entor o= 'X>:/ print=>nAnser is/:/ s#ant>?s>;s1:< n6str#mps1;s2:< ltnQ6': prQnt=>ntry again>:< else printt>n[ood>:< retum '/ l Sample Input Dennls(it#ie Sample Output Anser is/ [ood (esult us; Program > In*entor C> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Copy Count Mrite a C program to #opy one string to anoter string using loop. C program to #opy one string to anoter itout using inbuilt library =un#tion str#py: and #ount total number o= #ara#ters #opied. To to #opy one string to anoter and #ount total #ara#ters #opied it and itout using inbuilt string library =un#tion Sour#e Code 7in#lude 8stdio.9 int maln: #ar tet1_1''^. tet2_1''^< int i< BBprlnt=nter any string/ >:< s#an=>B9s> ;tet1 :1 IZ Copies tet1 to tet2 #ara#ter by #ara#ter B i6'< lletet1_l^l6': l tet2_i^ 6 tet1_i^2 iR l BB\aKes sure tat te string is -%LL terminated tet2_i^ 6 '<
print=>n"lrst strlng6?s>;tet1:l printt>nSe#ond strlng6?s>;tet2:< print=>notal #ara#ters #opied6B89d>; I:< return '/ l Sample Input S(\%nl*ersity Sample Output "+rrst string6S(\%ni*ersity Se#ond strlng6S"t\%nl*ersity otal #ara#ters #opied613 (esult us; Program >Copy Count > as been su##ess=ully ee#uted
Course/ C Syb0e#t Code/ . Con#atenate Code Mrite a C program to #on#atenate to di==erent strings into single string. To to #on#atenate to strings into one itout using str#at: library =un#tion. Adding to strings into one itout using inbuilt library =un#tion.C'n#atenation o= to strings is te pro#ess o= 0oining tem togeter to =orm a ne string. Con#atenation basi#ally 0oins te se#ond string a=ter =irst string. Con#atenation is sometimes also re=erred as binary addition o= strings i.e. operation. "or eample/ Code=or Min 6 Code=orMin Sour#e Code 7Qn#lude 8stdio.9 7de=lne \A]SIR 1'' int maln: i #ar tet1_\A]SIR^. tet2_\A]SlR^; output_\A]SIR^< rm i; 1< BB prlnt=>nnter =irst string/ >:1 s#an=V?s>.tet1:< BBprint=nnter se#ond string/ >:< s#an=>B89s>.tet2:2 i6'/ lletet1_l^l6': N output=i^ 6 tet1_i^I i< c B Copies tet2 to output string B 0 6 lletet2_0^l6': N outputiY 6 tet2_i^< i< ^< i BB\aKe sure tat te output is -%LL terminated output_l^ 6 '/ print=Vn"lrst string6B9s>; tet1:< print=>nSe#ond strlng6?s>; tet2:< print=>n"inal #on#atenated string6?s>. output:< return '< l Sample Input
S(\%nl*ersity LeamlngCentre Sample Output "+llZSt strlng6S"t\%ni*ersQty Se#ond string6LeamingCentre Tnal #on#atenated string6S(\%ni*ersityLearningCentre (esult us; Program > Con#atenate Code > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Con*ersion Code +'1 Mrite a C program to #on*ert loer#ase string to upper#ase string using inbuilt string library =un#tion strupr:internally #ara#ters in C are represented as an integer *alue Knon as ASCII *alue. Mi# means i= e rite A or any oter #ara#ter it is translated into a numeri# *alue in our #ase it is 5 as ASCII *alue o= A 6 &!. Tere at e need to do is =irst e need to #e#K eter te gi*en #ara#ter is loer#ase alpabet or not. I= it is loer#ase alpabet 0ust subtra#t 32 =rom it i# ill result in upper#ase alpabet Sin#e ASCII *alue o= A65; a6&! teir di==eren#e is &!+5 6 32:. Sour#e Code 7ln#Iude8stdlo.9 7de=lne \A]SlR 1'' BB\aimum sie o= te string int maln: I #ar strlng_\A]SlR^< int i< 1> (eads a string =rom user B BBprlnt=nnter your tet/>:< s#an=>?s>;strlng:< =ori6'< strlng_l^Q6'< i: I It I= #urrent #ara#ter is loer#ase alpabet ten #on*ert It to upper#ase. 1 i=string_I^96a @@ string_i^86: I string_i^ 6 strlng_l^+32< I l print=>n%pper#ase string/B9s>;string:< return '/ l Sample Input srmunl*ersity Sample Output %pper#ase string/S(\%-l)"ISl (esult us; Program > Con*ersion Code +'1 > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . Con*ersion Code +'2 Mrite a C program to #on*ert upper#ase string to loer#ase using inbuilt string library =un#tion strlr:. To to use strlr library =un#tion
in C programming. Internally #ara#ters in C are represented as an integer *alue Knon as ASCII *alue. Mi# means i= e rite a or any oter #ara#ter it is translated into a numeri# *alue in our #ase it is &! as ASCII *alue o= a 6 &!. Tere at e need to do is =irst e need to #e#K eter te gi*en #ara#ter is upper #ase alpabet or not. I= it is upper#ase alpabet 0ust add 32 to it i# ill result in loer#ase alpabet Sin#e ASCII *alue o= A65; a6&! teir di==eren#e is &!+5 6 32:. Sour#e Code 7ln#lude 8stdio.9 7de=lne \A]SlR 1'' BB\aimum sie o= te string int maln: l #ar string_\A]SlR^< lnt i< B (eads strlng =rom user I BBprlnt=nnter any string/:< s#an=?s>;strlng:< B=(uns a loop tlll last #ara#ter o= string tori6'< strlng_l^l6'< l: N i=string_l^96A @@ strlng_l^86R: l string_i^ 6 string_i^ 322 l l print=>nLoer #ase string/?s>; string:< return '< : Sample Input S(\%-I)(SILA(-I-[C-( Sample Output Loer #ase stringsrmuni*ersitylearning#entre (esult us; Program > Con*ersion Code +'2 > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . Count a String Mrite a C program to #ount total number o= alpabets; digits or spe#ial #ara#ters in a string using loop. To to =ind total number o= alpabets; digits and spe#ial #ara#ters in a string in C programming. Sour#e Code 7in#lude 8stdio.9 7dene \A]SlR 1'' BB\aimum sie o= te string lnt main: l #ar string_\A]SlR^< int alpabets; digits; oters; I< alpabets 6 digits 6 oters 6 i 6 '< iZ (eads a string =rom user 1 BBprInnter any string/>:/ s#an=>?sV;string:< BC Z Ce#Ks ea# #ara#ter o= string FB llestring_i^l6': l
i=strlng_l^96a @@ string_l^86: QQ strlng_l^96A @@ strlng_i^86R:: l alpabets< c else l=string_i^96' @@ strlng_l^86&: N digits< l else oters< c i1 c print=>nAlpabets6?d>; alpabets:< print=>nDlgits6Bed>; digits:< print=>nSpe#ial #ara#ters6?d>; oters:< return '/ l Sample Input S(\J%nQ*ersltyhLeaming@Centreh1 1 13 Sample Output Alpabets62! Digits64 Spe#ial #ara#ters64 (esult us; Program >Count a String > as been su##ess=ully ee#uted
#ourse/ C Wib0e#t Code/ . (e*erse String+ Mitout Library Mrite a C program to =ind re*erse o= a string itout library =un#tion. Sour#e Code 7in#lude 8stdio.9 7in#lude 8string.9 7de=lne \A]SlR 1'' BB\aimum sie o= te string lnt main: l #ar string_\A]SQR^; re*erse_\A]SQR^< int i; 0; len< 1> (eads string =rom user B BBprQnt=>nnter any string/>:< s#an=>?s>.string:< len 6 strlenstrlng:< l 6 '1 =ori6Qen+1/ l96'< i++: l re*erse_0^ 6 string_l^< 0< c re*erse_Q^ 6 ZO< pr1ntt>nOriginal string6?sn>; string:< print=>(e*erse string6B#s>. re*erse:< return '< l Sample Input S(\%ni*ersity Sample Output
Original string6S(\%ni*ersity (e*erse string6ytlsre*in%\(S (esult us; Program > (e*erse String+ Mitout Library> as been su##ess=ully ee#uted
Course/ C Stib0e#t Code/ . Print Inde To to =ind all o##urren#es o= a #ara#ter in a gi*en string using =or loop in C programming. Program to print all inde o= a #ara#ter in a gi*en string. Sour#e Code 7in#lude 8stdio.9 7ln#lude8string.9 7de=ine \A]SlR 1'' IB\aimum sie o= te string int main: l #ar a< #ar string_\A]SlR^< int i;len< =Bprlntt>nnter any #ara#ter to sear#>:< s#an=>?#>.@a:< BBprlnt=nnter any stringR:/ s#an=>?s>;strlng:l Qen6strlenstring:< BB(uns a loop tlll te -%LL #ara#ter is =ound =ori6'< i86len< i: l i=string_i^ 66 a: N print=>n?# is =ound at inde B'd>. a; i:< l l return '< l Sample Input u srmunl*ersity Sample Output u is =ound at inde 3 (esult us; Program > Print Inde > as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C T . \aimum "reYuen#y To to Wnd igest =reYuen#y #ara#ter in a string using loop in C programming."ind =reYuen#y o= ea# #ara#ters in te string and store it in some array o= integers. "ind maimum element in te array. \aimum element in te array ill te be maimum o##urring #ara#ter in te string. Sour#e Code 7in#iude 8stdio.9 7de=lne \A]SlR 1'' BB\aimum sie o= te string 7de=ine \A]CTA(S 255 BB\aimum #ara#ters alloed int maln:
#ar string_\A]SlR^< int =reYuen#y_\A]CTA(S^< BBStores =reYuen#y o= ea# #ara#ter int i 6 O; ma< int as#ii< BBprlnt=nter any string/ >:< s#an=?s>;string:< IZ Initialies =reYuen#y o= all #ara#ters to ' I =ori6'/ i8\A]CTA(S< l: N =reYuen#y_Q^ 6 '/ c B "inds =reYuen#y o= ea# #ara#ters 1 i6'/ llestring_i^ l6 ': N as#ii 6 int:string_l^< =reYuen#y_as#iQ^ 6 1< i1 i B "inds maimum =reYuen#y B ma 6 '2 =ori6'< i8\A]CTA(S< l: l i==reYuen#y_l^ 9 =reYuen#y_ma^: ma 6 i< c print=>nTigest =reYuen#y o= ?# is ?d tn>; ma; =reYuen#y_ma^:< return '1 l Sample input srmuni*ersity Sample Output Tigest =reYuen#y o= i ls 2 (esult us; Program >\aimum "reYuen#y> as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C 11 . \inimum "reYuen#y To to Wnd loest =reYuen#y #ara#ter in a string using loop in C programming Sour#e Code 7in#iude 8stdio.9 7de=ine \A]SlR 1'' BB\aimum sie o= te string 7de=lne \A]CTA(S 255 BB\aimum #ara#ters alloed int maln: i #ar string_\A]SlR^< int =reYuen#y_\A]CTA"tS^/ BlStores =reYuen#y o= ea# #ara#ter int i 6 O. min/ int as#li< BBprint=nnter any string/>:< s#an=>?s.string:< B Initialies =reYuen#y o= all #ara#ters to ' I =ori6'< i8\A]CTA(SI Q: N l
=reYuen#y_Q^ 6 '/ I "inds =reYuen#y o= ea# #ara#ters VB i6'< Qiestring_i^ J6 ': N as#ii 6 int:string_i^/ =reYuen#y_as#iY 6 1< i/ c . IZ "inds minimum =reYuen#y I min 6 '< ='ri6'< i8\A]CTA"tS/ i: N i==reYuen#y_i^ i6 ': N i==reYuen#y_min^ 66 O QQ =reYuen#y_Q>i 8 =reYuen#y_min^: min 6 i< i i print=>nLoest =reYuen#y o= ?# is Bod>; min. =reYuen#y_min^:< return '< l Sample Input madam Sample Output Loest =reYuen#y o= d is 1 (esult us; Program > \inimum "reYuen#y > as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C T . "reYuen#y o= ea# Mrite a C program to #ount =reYuen#y o= ea# #ara#ter in a string using loop Sour#e Code 7In#lude 8stdio.9 7ln#lude 8string.9 7de=Ine \A]SlR 1'' BB\aimum sie O= te string lnt maln: #ar string_\A]SlR^< lnt i; len< lnt =reYuen#y_2^< BZ (eads a strlng =rom user 1 BBprQnt=nter any string/ >:< s#an= B9s>;strlng:< len 6 strlenstrlng:< BZ Initialies =reYuen#y o= ea# #ara#ter to ' B =ori6'< i82I i: N lreYuen#y_Q^ 6 '3 c B "il1dS tOt3Q number O= OOC%MUTCS O= ea# #ara#ter B =ori6'< i8len< i: N IZ I= te #urrent #ara#ter is loer#ase alpabet B i=string_l^96a @@ string_i^86:
=reYuen#y_string_l^ + &!^< l else l=string_l^96A @@ string_Q^86R: l =reYuen#y_strlng_i^ + 5^< l l B( Z Prints te =reYuen#y o= all #ara#ters In te string I print=>n"reYuen#y o= all #ara#ters in te gi*en string/ n>:< ='ri6'< i82< i: N B I= te #urrent #ara#ter ls In gi*en string VI i=treYuen#y_i^l6': l print=>?# 6 ?dn>. i&!:; =reYuen#y_i^:< c l return '/ l Sample Input srmunl*ersitylearning#entre Sample Output "reYuen#y o= all #ara#ters in te gi*en string/ a61 61 88CZm>/G3`DO ..-Q:+`E;p .;<9 63 61 (esult us; Program > "reYuen#y o= ea#> as been su##ess=ully ee#uted
#ourse/ C X/.lb^eC Code/ . Alpabeti#al Order Mrite a program i# ill read a string and rerite it in te alpabeti#al order. "or eample; te ord S(I-[ sould be ritten as [I-(S. Sour#e Code 7in#lude8stdlo.9 7In#lude8strlng.9 lnt maln: l #ar a_3'^;temp< int n6'0;i< BBprintt>mnter te string/>:< s#ant>?s>;a:< ilea_n^l6': l n< l =ori6'a_il9ali11:
l temp6a__^< a_i^6a_i1^I a_^1^6temp< l l l print=>ne string in alpabeti#al order is/>:< =orl6'B6#;a_i^:< l retum '/ l Sample Input string Sample Output e strlng in alpabeti#al order is/ginrst (esult us; Program > Alpabeti#al Order > as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C 11 . (emo*e String 1st O##urren#e Mrite a C program to read any string =rom user and remo*e =irst o##urren#e o= a gi*en #ara#ter =rom te string Sour#e Code 7in#lude 8stdio.9 7ln#lude 8string.9 7dellne \A]SlR 1'' BB\aimum sie o= te string B> "un#tion de#laration I *oid remo*e"irst#ar Z; #onst #ar:< lnt main: = #ar string_\A]SlR^< #ar to(emo*e< BJprint=>nnter #ara#ter to remo*e =rom string/ >:< to(emo*e 6 get#ar:< BBpr1nt=>nnter any string/ >:1 s#an=V?s>;strlng:< remo*e"irststring; to(emo*e:/ print=>nOutput/B89s> string:< return '/ l B.. "un#tion to remo*e Wrst o##urren#e o= a #ara#ter =rom te string. B *oid remo*e"lrst#ar V string; #onst #ar to(emo*e: t lnt i< int len 6 strlenstring:< i6'/ 1 (un loop until te Wrst o##urren#e o= te #ara#ter is not =ound 1 lleKlen @@ strlng_i^Q6to(emo*e: i< BZ V Si=t all #ara#ters rigt to te posltlon =ound abo*e to one pla#e le=t
F1 lleKlen+1: N string_i^ 6 string1^< i< 1 B \aKe te last #ara#ter null B string_i^ 6 '< l Sample Input l srmuni*ersitylearning#entre Sample Output Output/srmun*ersltyleaming#entre (esult us; Program > (emo*e String 1st O##urren#e> as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C 11 . (emo*e All o##urren#e C program to remo*e all o##urren#es o= a #ara#ter =rom te string Sour#e Code 7In#lude 8stdio.9 7ln#lude 8string.9 7de=lne \A]SlR 1'' BB\aimum sie o= te string B> "un#tion de#laration ZB *oid remo*eLast#ar Z; #onst #ar:< int main: i #ar string_\A]SlR^< #ar to(emo*e< B=print=_>nter #ara#ter to remo*e =rom string/>:< to(emo*e 6 get#ar:< BBprint=>nnter any string/>:< s#an=>?s> ;strl ng:< remo*eLaststrlng; to(emo*e:< printt>nOutput/?s>;string:< return '< l 1.. "un#tion to remo*e last o##urren#e o= a #ara#ter =rom te string. B *oid remo*eLast#ar stnng; #onst #ar to(emo*e: l int l; lastPosition< int len 6 strlenstring:< QastP'sition 6 +1< i6'< liei8ien: N i=string_i^ 66 to"temo*e: l IastPosition 6 I< c iI 1 itlastPosition l6 +1:
N i 6 lastPosition/ It Z Si=t all #ara#ters rigt to te position =ound abo*e to le=t F1 iQei8len+1: N string_i^ 6 string_i1^< i< c l IZ \aKe te last #ara#ter null B strlng_i^ 6 '< l Sample Input a madam Sample Output Outputmadm (esult us; Program > (emo*e All o##urren#eV as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C 11 . (emo*e String 1st O##urren#e Mrite a C program to read any string =rom user and remo*e Wrst o##urren#e o= a gi*en #ara#ter =rom te string Sour#e Code 7in#lude 8stdio.9 7de=ine \A]SlR 1'' BB\aimum sie o= te string BZ "un#tion de#laration B *oid repla#e"Qrst#ar string; #ar to(epla#e. #ar repla#elt:< int main: l #ar string_\A]SlR^; to(epla#e; repla#elt/ BBprint=nter any strlng/>:< s#an=>?s>;string:1 BBprinttnter #ara#ter to repla#et>:< soant ?#>. @to(epla#e:< 1B prlnttnter #ara#ter to repla#e BoC lt/>. to(epla#e:< s#an=> ?#>; @repla#eMit:< printt>nString be=ore repla#ing/?s>; string:< repla#e"irststrlng; to(epla#e. repla#elt:/ printt>nString a=ter repla#ing/Bus>; string:< return '/ i PO (epla#es te =irst o##urren#e o= a #ara#ter it anoter in gi*en string. I *oid repla#e"lrst#ar Z string; #ar to(epla#e; #ar repla#elt: int i6OI BZ (uns till te end o= string B llestring_i^ l6 ': N IZ I= an o##urren#e o= #ara#ter ls =ound >B
i=string_Q^ 66 to(epla#e: t string_i^ 6 repla#e)lWt< breaK/ c i< l l Sample Input srmuna*ersityiearning#entre a i Sample Output String be=ore repla#ingsrmuna*ersityleaming#entre String a=ter repla#ing/srmuni*ersitylearning#entre (esult us; Program > (emo*e String 1st O##urren#e> as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . Cara#ter tra#t Mrite a program to etra#t a portion o= a #ara#ter string and print te etra#ted string. Assume tat m #ara#ters are etra#ted; starting it te nt #ara#ter. Sour#e Code 7in#Iude8stdlo.9 7dene \A] 5' int maQn: i #ar Str1_\A]^/ int l;m;n.0< BBprint=>nter A String/>:< s#ant>?s>.Str1:< J1printt>nnter -umber o= Cara#ters Mi# ou Mant to tra#t/>:< s#an=>?d>.@m:/ IBprint=>nnter Ueginning Inde =rom Mi# % Mant to tra#tV:/ s#an=>?d>;@n:/ print=>ntra#ted String is/>:< =ori6n+1?#.Str1_i^:< i retum O< i Sample Input S(\%ni*ersityLeamingCentre 1' 5 Sample Output tra#ted String is/ni*ersityL (esult us; Program > Cara#ter tra#t> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . (upee -ame Mrite a program tat reads te #ost o= an item in te =orm ((((.PP ere ((((
denotes rupees and PP denotes paise: (e=er sample input and output. Sour#e Code 7ln#lude8stdlo.9 rm maln: l oat Cost;Pai;(e;0/ lnt (up;i;(< BBprint=>nnter Cost o= an I\ 1:< s#an=>?=>;@Cost:< (up 6 Cost< Pal 6 Cost + (up:1''< i6(upB1''< sit#l: #ase 1/ prlnt=>O- T%-D(D >:< breaK/ #ase 2/ print=MO T%-D(D >:< breaK< #ase 3/ printtT( T%-D(D >:< breaK< #ase 4/ prlnt=>"O%( T%-D(D V:< breaK< #ase 5/ printt>"l) T%-D(D >:/ breaK< #ase / print=>Sl] T%-D(D >:< breaK/ #ase !/ prlntt>S)- T%-D(D >:< breaK< #ase $/ printt>l[T T%-D(D >:< breaK< #ase &/ prlnt=>-l- T%-D(D >:< breaK/ l l6(up?1''< (6lB1'/ (e6oat:lB1 '< sit#(: l #ase 1/ print1>->:< breaK/ #ase 2/ prlnt=M- >:< breaK< #ase 3/ print=>Tl( :< breaK< #ase 4/ print=>"O%( >:< breaK< #ase 5/ prlnt=>"l" >:< breaK< #ase / prlntt>Sl] >:< breaK< #ase !/ prlnt=>S)- >:< breaK/ #ase $/ print=>l[T >:< breaK< #ase &/ print=>-l- >:< breaK< l (6(e+(:1'< sit#(: #ase 1/ prlnt=>O->:< breaK< #ase 2/ prlnt=>MO >:< breaK< #ase 3/ prlnttT( >:< breaK< #ase 4/ print=>"O%( >:< breaK< #ase 5/ prlnt=>"l) :< breaK/ #ase / prlnt=>Sl] :1 breaK< #ase !/ prlntt>S)- >:< breaK< #ase $/ prlnt=>l[T >:< breaK/ #ase &/ printt>-l- >:< breaK< l printt>A-D PAIS >:< i6PalB1'< (e6oat:PaIB1'< (6(e+l:Z1'/ sit#l: l
#ase 1/ prlntt>-V:/ breaK< #ase 2/ prlnt=>M- >:< breaK< #ase 3/ prlnt=>Tl( >:< breaK< #ase 4/ print=>"O%( >:< breaK< #ase 5/ prlnt=>"ll+ >:< breaK< #ase / print=>Sl] >:< breaK< #ase !/ prInt=>S)- >:< breaK< #ase $/ prlntt>l[T >:< breaK< #ase &/ prlntt>-l- >:< breaK< l sit#(: #ase 1/ prlnt=>O->:< breaK/ #ase 2/ prlnt=>lMO >:< breaK/ #ase 3/ print=>T( >:< breaK< #ase 4/ prlnt=>"O%( >:< breaK< #ase 5/ prlnt1>"l) :< breaK< #ase / prlnt=>Sl] >:/ breaK< #ase !/ prlnt=>S)- >:< breaK< #ase $/ print=>l[T >:< breaK< #ase &/ prlnt=>-l- V:< breaK< l retum O2 l Sample Input 1'4.3 Sample Output O- T%-D(D "O%( A-D PAIS TI( (esult us; Program > (upee -ame > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . String Compare Mrite a program to read to strings and #ompare tem using te =un#tion str#mp: and print a message tat te =irst string is eYual; less or greater tan te se#ond one. Sour#e Code 7in#lude8stdlo.9 7de=Qne \A] 5' int maln: t #ar Str1_\A]^;Str2_\A]^/ BBprintt>nnter "irst String/:/ s#an=>?s>;Str1 :< =usstdin:< BBprintt>nnter Se#ond String/>:< s#an=>?s>.Str2:< itstr#mpStr1 ;Str2:66': printt>nU't Strings are Yual>:< else l=str#mpStr1.Str2:8': printt>n"irst String is Less an Se#ond String>:/ else printt>n"irst String is [reater an Se#ond String>:< retum '< : Sample Input S"t\%nl*ersity
S(\ Sample Output "irst String is [reater an Se#ond String (esult us; Program >String Compare > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Conse#uti*e String Copy Mrite a program tat ill #opy m #onse#uti*e #ara#ters =rom a string s1 beginning at position n into anoter string s2 Sour#e Code 7in#lude8stdlo.9 7de=ine \A] 5' *oid main: #ar Str1_\A]^;Str2_\A]^< lnt i;m;n;^< Biprint=>nnter A StrQng/>:/ s#an=>B89s>;Str1 :< B.print=>nnter -umber o= Cara#ters Mi# ou Mant to Copy/>:< s#an=>?d.@m:/ BBprintt>nnter Ueginning Inde =rom Mi# ou Mant to Copy>:< s#ant>?d.@n:I torl6n+1.06'/i8mnnCopied String is/?s>.Str2:< l Sample Input S(\%nl*ersity 5 1 Sample Output Copied String ls/S(\%n (esult us; Program >Conse#uti*e String Copy> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Student Dire#tory Mrite a program to #reate a dire#tory o= students it roll numbers.e program sould display te roll number =or a spe#i=ied name and *i#e+*ersa. Sour#e Code 7in#lude8stdlo.9 7dene \A] 5' int maQn: l #ar Stu-ame_\A]^_\A:^;-ame_\A]^< int (oQQ-o_\A]^;n;l.(oll.lnde< BBprint1VnTo \any Student -ame ou Mant to nter>:< s#ant>?d>;@n:< BBprint=>nnter (oll -o and Students -amet>:< =ori6'
l s#an=>?d>.@(oll-o_l^:1 s#an=>?s>. Stu- ame_i^:< l BBprint=>nnter Student (oll -o i# ou ant to Sear#/>:< s#an=>?dV;@(olI:< =orl6'n-ame o= Student is/ B9s ose (oll -o is/?d;Stu-ame_lnde^;(oll:< Biprlntt>nnter Student -ame i# ou ant to S$3lZCI>:R s#an1>?s>;-ame:< =orl6'/i8nn(olQ -o o= Student/Bed ose -ame is/ ?s>;(oil-o_lnde^;Stu-ame_lnde^:1 retum O< l Sample Input 5 1'' irtigaDe*i 1'1 ,onUlessin 1'2 Sel*amary 1'3 Crlstura0 1'4 (a0ee*suKumaran 1'4 irtigaDe*l Sample Output -ame o= Student ls/ (a0ee*suKumaran ose (oll -o is/1'4 (oll -o o= Student/1'' ose -ame is/lrtlgaDe*i (esult us; Program >Student Dire#tory> as been su##ess=ully ee#uted
Course/ C 11 Sub0e#t Code/ . String Patt [i*en a string Sour#e Code 7in#lude8stdio.9 mt main: N #ar Str_^6>12345 int i;0.K;l< ='Qi6'
='r06'.Q6Q/086i 11> print=>B9#V.Str_l^:< : l6l+22 =orK6'B9C>.Str_l^:I print=>n>:< : c retum '/ : Sample Input ' Sample Outpu 1 232 34543 45!54 5!$&$!5 (esu us; Program ern #a !$& l: I -S rstr_^ 612345!$&< Mrite a program tat displays te =olloing/ 1 2 3 2 3 4 5 4 3 4 5 ! 5 4 5 ! $ & $ ! 5 tring Pattern> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . String Lengt Mrite a C program to =ind lengt o= a string using loop. To to =ind lengt o= a string itout using in+built library In C tere is a general #on#ept tat e*ery string must terminate it a spe#ial #ara#ter tat is -%LL #ara#ter i# is also es#aped. Ten#e e use a tis basi# #on#ept to =ind lengt o= string. Mat e need to do is tra*erse entire string #ara#ter by #ara#ter till a -%LL #ara#ter is =ound and in ea# iteration in#rement te #ounter *alue. Sour#e Code 7ln#lude 8stdio.9 int maln: l #ar tet_1''^< IZ De#lares a string o= sie 1'' >B Int inde6 '< BBprlnt=>nter any strlng/ >:< s#an=V?s>;tet:/ iletetW nde^ l6': l lIld$]1+I l print=>nLengt o= ?s6?d>; tet; inde:< return '< l Sample Input
S(\%ni*ersityLeamingCentre Sample Output Lengt o= S"t\%nQ*ersityLeamingCentre62! (esult us; Program >String Lengt> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . urbo Sort [i*en te list o= numbers; you are to sort tem in non de#reasing order. lnputt X te number o= numbers in list; ten t lines =ollo _t 86 1'>^. a# line #ontains one integer/ - _' 86 - 86 1'>^ Output Output gi*en numbers in non de#reasing order. Sour#e Code 7in#lude 8stdio.9 Int array_1'''''1^ 6 NOc< int main:N Int i;0< s#an=>B6d>;@0:R int < =or i6O/i80/i:N s#an=>B9d>;@:< array_^< l =or i6O;i:< array=l^++< c l retum '< l Sample Input 543211 Sample Output %1,9O,i:fFfF (esult us; Program >urbo Sort> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Ce= And Operators Ce= as 0ust started Programming; e is in =irst year o= ngineering. Ce= is reading about (elational Operators.(elati'nal Operators are operators i# #e#K relationsip beteen to *alues. [i*en to numeri#al *alues A and U you need to elp #e= in =inding te relationsip beteen tem tat is; "irst one is greater tan se#ond or; "irst one is less tan se#ond or; "irst and se#ond one are eYual. Input "irst line #ontains an integer ; i# denotes te number o= test #ases. a# o= te lines #ontain to integers A and U. Output "or ea# line o= input produ#e one line o= output. is line #ontains any one o= te relational operators 8;9;6 Constraints 1 86 861'''' 1 86 A; U 861''''''''1 Sour#e Code 7ln#lude8stdlo.9 Int main:
l int t;a.b1 s#an=>?d>;@t:3 llet++: N s#an=>?dB89d>.@a;@b:< ita9b: print=>n9>:< l=a8b: print=>n8>:< l=a66b: print=>n6>:< c return '< l Sample Input 3 1'2' 2'1' 1'1' Sample Output 8 9 (esult us; Program > Ce= And Operators> as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . Array \ode Mrite a program to =ind te mode o= te elements in te array. e mode in a list o= numbers re=ers to te list o= numbers tat o##ur most =reYuently. It is important to note tat tere #an be more tan one mode and i= no number o##urs more tan on#e in te set; ten tere is no mode =or tat set o= numbers. Input and Output "ormat/ Input #onsists o= n1 integers ere n #orresponds to te number o= elements in te array. e =irst integer #orresponds to n and te net n integers #orrespond to te elements in te array. (e=er sample input and output =or =ormatting spe#i=i#ations. Assume tat te maimum number o= elements in te array is 2'. Assume tat in te input dataset tere is 1 mode or no mode at all. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdlo.9 7ln#Qude8stdQQb.9 lnt #reateArrayint:< *oid readlementlnt;int :< *oid array\odeint;lnt Z:< lnt main: = lnt a;n< BBprint=>nter te number o= elements in te arrayln>:< s#an=>?d>.@n:/ a6#reateArrayn:< readIementn;a:< printt>e mode o= te array ls>:< array\oden;a:< retum O< l
lnt >#reateArrayint n: l lnt a< a6int >:maQlo#nZsieo=Int::< retum a< l *oid readlementlnt n;int a: l lnt ii BBprint=>nter te elements in te arrayn>:< =ori6'?d>;ai:< l l *oid array\odeint n.int Za: l lnt l;0;#6';K< =ori6'/i8nai:66ai:: mm K6Zai:< l l l >C66': print=> none>:< l else i=#9': print=> ?d>;K:/ l l Sample Input 5 24235 Sample Output e mode o= te array ls 2 (esult us; Program >Array \ode > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . %PP( (IA-[%LA( \A(I] An upper triangular matri is a sYuare matri in i# all te elements belo te diagonal are ero. at is; all te non+ero elements are in te upper triangle/ Mrite a C program to =ind eter a gi*en matri is an upper triangular matri or not. Input "ormat/ e input #onsists o= nZn1: integers. e =irst integer #orresponds to te number o= rosB#olumns in te matri. e remaining integers #orrespond to te elements in te matri. e elements are read in roise order; =irst ro =irst; ten se#ond ro and so on. Assume tat te maimum *alue o= m and n is 5. Output "ormat/ Print yes i= it is an upper
triangular matri . Print no i= it is not an upper triangular matri Sour#e Code 7in#lude8stdlo.9 7ln#lude8stdlQb.9 int >#reateArrayint:< *oid getQementsint>;lnt:< *oid trianguQar\atriint;int:< int main: Int >a;n< s#an=>B89d>.$tn:R a6#reateArrayn:< getlementsa;n:< triangular\atra;n:2 retum '< l int >#reateArrayint n: lnt i.Va< a6Int :mallo#nFsieo=int::/ =ori6'a;lnt n: int i;0< =orQ6'?d>.aI:0:< l l l *oid trianguQar\atriint >a;int n: i Int i;0< =orQ6'/i8nno>:/ retum/ l l l print=>yes>:/ l Sample Input
2 1 2 ' 3 Sample Output yes (esult us; Program > %PP( (IA-[%LA( \A(I] > as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C T . Array + Sum o= *en -umbers Mrite a program to Wnd te sum o= te e*en numbers present in an array using re#ursion. Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ations. Sour#e Code 7ln#lude8stdio.9 7ln#lude8stdllb.9 lnt sum*enArrayint Za.Int li;int sie: lnt s6'< ltsle66': l retum s< l BBprintt>?dn>;Ql:< l=asie+1::?266O: l s6sasQe+1::/ BBprint=>?dn>;s:< l retum ssum*enArraya;li;sie1:::< l Int maln: l lnt >a;ll;sie;b< BBprint=>nter te number o= elements in te arrayn>:< s#an=>?d>.@sle:< BBprintt>nter te elements in te arrayn>:< a6int:mallo#siesieo=int::< =orIi6'/li8sie?d>.ali::< l b6sum*enArraya;li;sie:1 printt>e sum o= te e*en elements ln te array is/?d>;b:< retum '< : Sample Input 5 4$1'12 Sample Output e sum o= te e*en elements in te array is/4' (esult us; Program >Array + Sum o= *en -umbers> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . (e#ursion $ / \aimum lement in Array Mrite a program to =ind te maimum element in an array using re#ursion. Input and Output "ormat/ Input #onsists o= n1 integers (e=er sample input and output =or =ormatting spe#i=i#ations. All tet in bold #orresponds to input and te rest #orresponds to output Sour#e Code 7in#lude8stdio.9 7ln#lude8stdlQb.9 int ma6'< lnt Wnd\alementint Zarr;int sie: l lisle66': retum ma< l iiarrsie+1::9ma: l ma6arrsle+1:::< BBprint=>ma ?dn.ma:< l else ma6ma< Brprint=>ma ?dnma:/ l retum =lnd\alementarr;sleE1::< l int main: l int Zarr;sie;i< BBprint=>nter te sie o= te arrayn>:< s#an=>?d>.@sle:2 BBprint=>nter ?d elements o= an arrayn>;sie:< arr6int :mallo#siesieo=int::I =ori6'?d>;arri::< l =ind\aQementarr;sle:< print=>\almum element in te array is ?d>.=ind\aQementarr.sle::< retum '< : Sample Input 251!42 Sample Output \aimum element in te array is ! (esult us; Program >(e#ursion $ / \aimum lement in Array> as been su##ess=ully ee#uted
Course/ C Sib0e#t Code/ . (e#ursion ! / Sum o= elements in Array Mrite a program to #ompute te sum o= elements in an array using re#ursion. Input and Output "ormat/ Input #onsists o= n1 integers (e=er sample input and output =or =ormatting spe#i=i#ations. All tet in bold
#orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdio.9 7ln#lude8stdlQb.9 int WndSumint a;int n: mt s6O< lln66': retum H1 l s6sFan+1::< BBprint=>?dn;s:< retum s=lndSuma;n+1::< l Int maln: t Int n;Za.l;#I BBprint=>nter te number o= elementsn:< s#an=>?d.@n:< BBprint=>nter te elements in te arrayn>:< a6Int:malIo#nsieo=int::< =ori6'/i8n?d>.al::< l #6=indSuma.n:< print=>e sum o= te elements in te array is ?d>.#:< retum '< l Sample Input 5 54321 Sample Output e sum o= te elements in te array ls 15 (esult us; Program > (e#ursion ! / Sum o= elements in Array> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . (e#ursion 5 / -umber o= digits Mrite a program to =ind te number o= digits in a number using re#ursion. Input and Output "ormat/ Input #onsists o= a nonnegati*e integer. (e=er sample input and output =or =ormatting spe#i=i#ations. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 7in#lude8stdlQb.9 int #ompute-umint n: = int #6'< l=n?1'66n: l retum 1/ l l=n?1'l6':
l C< l #68/#ompute-umnB1':< retum #/ l int main: l Int n;b< BBprint=>nter te *alue o= nn>:< s#an=>?d>;@n:/ b6#ompute-umn:< print=>e number o= digits in ?d is B9d;n;b:< retum '< l Sample Input 123 Sample Output e number o= digits in 123 is 3 (esult us; Program >(e#ursion 5 / -umber o= digits> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . (e#ursion 4 / Sum o= digits Mrite a program to =ind te sum o= digits in a number using re#ursion. Input and Output "ormat/ Input #onsists o= a nonnegati*e integer (e=er sample input and output =or =ormatting spe#i=i#ations. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdQo.9 7ln#lude8stdlQb.9 lnt #omputeSumint n: i lnt s/ Int K6n< ileK: l s6K?1'< retum s#omputeSumKB1':< l l int main: l Int n< BBprint=>nter te *alue o= nn>:< s#an=>?d>;@n:/ #omputeSumn:< print=>e sum o= digits in ?d is B89d>;n;#omputeSumn::< retum '< l Sample Input 43 Sample Output e sum o= digits in 43 is ! (esult us; Program >(e#ursion 4 / Sum o= digits> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . (e#ursion 3 / Compute an Mrite a program to #ompute a>n a poer n: using re#ursion. Input and Output "ormat/ Input #onsists o= 2 integers. (e=er sample input and output =or =ormatting spe#i=i#ations. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdQo.9 7ln#lude8stdlQb.9 lnt #omputePoerint a;int n: l l=n66O: retum 1< l else i=n661: l retum a< l retum #omputePoera;n+1:a< l lnt maln: Int a;n< BBprint=>nter te *alue o= an>:< s#an=>?d>.@a:< BBprint=>nter te *alue o= nn>:< s#an=>?d>.@n:< #ompute Poera; n:< print=>e *alue o= Bod poer Bod is Bed>;a;n;#omputePoera.n::< retum '< l Sample Input 2 $ Sample Output e *alue o= 2 poer a is 25 (esult us; Program >(e#ursion 3 / Compute an> as been su##ess=ully ee#uted
Course/ C =rbie#t #o de/ . "a#torial %sing ( Mrite a program to #o sample input and out P Sour#e Code 7in#lude8stdio.9 7ln#lude8stdQQb.9 int #ompute"a#torialint n: l=n661QQn66O: retum 1 < l
else retum n#ompute"a#torlal l l Int main: Int n< BBprint=>nter te *alue o= s#an=>B89d>;@n:< #ompute"a#torialn:< print=>e =a#torial o= ?d retum '< l Sample Input 5 Sample Output e =a#torial o= S is 12' (esult us; Program >"a#t >+1: CC% mp ut = nn>:< is B89dV oria rsion +1 ute te =a#torial o= a number using re#ursion. Input and Output "ormat Input #onsists o= an integer (e=er or =ormatting spe#i=i#ations. All tet in bold #orresponds to input and te rest #orresponds to output .n;#ompute"a#toriaQn::< I %sing (e#ursion +1> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code . "a#torial o= a number Mrite a program to =ind te =a#torial o= a number using =un#tions Input "ormat Input #onsists o= 1 integer Output "ormat Output #onsists o= a single integer (e=er sample output =or =ormatting details Sour#e Code 7ln#lude8stdQo.9 7in#lude8string.9 int ta#torialQnt:< int main: l Int n;=a#t< s#ant>?d>.$+n:< =a#t6=a#toriain:< printt>?d>;=a#t:/ retum '< l int =a#torialQnt n: i int i.=a#t61< =orQ61
=a#t6=a#ti< BBprint=>?dn>;=a#t:I l retum ta#t< : Sample Input 3 Sample Output s (esult us; Program > "a#torial o= a number> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . "un#tions+Lu#Ky String Mrite a program to =ind eter te gi*en string is Lu#Ky or not. A string is said to be lu#Ky i= te sum o= te as#ii *alues o= te #ara#ters in te string is e*en. (e=er =un#tion spe#i=i#ations =or te =un#tion details. e =un#tion a##epts a pointer to a string and returns an int. e return *alue is 1 i= te string is lu#Ky and ' oterise. Input and Output "ormat/ Input #onsists o= a string. Assume tat all #ara#ters in te string are loer#ase letters and te maimum lengt o= te string is 1''. (e=er sample input and output =or =ormatting spe#i=i#ations. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 7ln#lude8string.9 int #e#KLu#Ky#ar :< int #e#KLu#Ky#ar Fa: l lnt sum6';l< =orl6'nter te input stringn>:< s#an=>?s>;a:< =ori6'B9#>.aW^:< l sum6oe#KLu#Kya:< l=sum661: l
printt> is lu#Ky:< l else l printt> is not lu#Ky>:< l retum '< l Sample Input anlta Sample Output anlta is not lu#Ky (esult us; Program > "un#tions+Lu#Ky String > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . LOM( (IA-[%LA( \A(I] A loer triangular matri is a sYuare matri in i# all te elements abo*e te diagonal are ero. at is; all te non+ero elements are in te loer triangle/ Mrite a C program to =ind eter a gi*en matri is a loer triangular matri or not. Input "ormat/ e input #onsists o= n>n1: integers. e =irst integer #orresponds to te number o= rosB#olumns in te matri. e remaining integers #orrespond to te elements in te matri. e elements are read in roise order; =irst ro =irst; ten se#ond ro and so on. Assume tat te maimum *alue o= m and n is 5. Output "ormat/ Print yes i= it is a loer triangular matri . Print no i= it is not a loer triangular matri. Sour#e Code 7ln#lude8stdlo.9 7ln#lude8stdlQb.9 lnt #reateArrayint:< *oid getIementsint>;lnt:< *oid trianguQar\alriint>;int:< Int maln: l int >a;n< s#ant>?d>.@n:2 a6#reateArrayn:< getlementsa;n:< triangular\atra;n:2 retum '< l int >#reateArrayint n: l lnt >a;i/ a6Int>:mallo#nsieo=int::1 =orl6'/i8nal:6lnt:maQQo#nsieo=int::< l retum a/ l *oid getQementsint>a;int n: t int L^< =orl6'/i8n
=or06'<08n<0: l s#an=>?d>.al:0:< l l l *oid triangular\atriint>a;int n: l lnt L^< =or06'/08n<0: l =orl6'?d >;0:< BBprint=>?dn>;i:< BBprint=>?d.ai:0:::< l else i=Zai:0::J6':@@09i:: l prlntt>no>:< return< l l l print=Vyes>:< l Sample Input 2 1 ' 2 a Sample Output yes (esult us; Program > LOM( (IA-[%LA( \A(I] > as been su##ess=ully ee#uted
Course/ C Wlbie#t Code/ . S\\(IC \ A symmetri# matri or not. Input "orma se#ond integer #or e elements are r Sour#e Code 7ln#lude8stdlo.9 7ln#lude8stdlQb.9 A(I] using "un#tion is a sYuare matri tat is eYual to its transpose. Mrite a C program to =ind eter a gi*en matri is a sYuare matri t/ e input #onsists o= mFn2: integers. e =irst integer #orresponds to m; te number o= ros in te matri and te responds to n; te number o= #olumns in te matri. e remaining integers #orrespond to te elements in te matri. ead in roise order; =irst ro =irst; ten se#ond ro and so on. Assume tat te maimum *alue o= m and n is 1'. int >#reateArrayint;lnt:< *oid getlementsint>;i *oid symmetrl#\atriin
int maQn: t int >a.ros;#olumns< s#an=>?d>.@ros:< s#an=>?d;@#oQumns:< a6#reateArrayros;#oQ BBb6#reateArrayros;oo getlementsa;ros;#oQ symmetri#\atrQa;ros retum '< i int >#reateArrayint ro t int i;>a< a6intV:maQQo#rossl =ori6' int l;0< =orl6'?d.ai:^::< : : : *oid symmetrl#\atriln int i;0;#6'< =ori6'lZ$i:i::66al #< i l l BBprint=>?d>.#:< l=#66rosZ#oQumns:: print=>Symmetri#>:< l else t print=>-ot Symmetri#: l l Sample Input 2 2 4 5
5 4 Sample Output Symmetri# (esult us; Program >S nt;int:< t>;int;lnt:< umns:< lumns:< %mnS:R ;#olumns:< s;int #olumns: eo=intZ::I mnssieo=lnt:::< a;Int ros;int #olumns: t >a;int ros.int #olumns: :i::: s \\(IC \A(I] using "un#tion> as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . %-I"O(\I \A(I] using "un#tion %ni=ormity matri is a matri in i# all te elements in te matri are eiter #ompletely e*en or #ompletely odd Sour#e Code 7ln#lude8stdIo.9 7in#lude8stdlib.9 int >#reateArrayint:I *oid getlementsint>;lnt:< *oid uni=ormityDlagonaQsint>;lnt:I Int main: l lnt >a;n< s#an=>?d.@n:< a6#reateArrayn:< getlementsa;n:< uni=ormityDiagonaIsa;n:< retum '< l lnt >#reateArrayint n: l int >a;i< a6Int>:malQo#nsieo=int::I =ori6'a;int n: l lnt l;0< =orl6'
s#an=>?d>.al:^::< l l l *oid uni=ormityDlagonalsint a;int n: l int l;0;b6'.#6';d;e< =ori6'i66l: 816Zai:ll:< l=d66e:@@dJ6':: l printt>no>:< retum< l l l e6d< l =ori6'?dn>;e:< l l >66>>llQb66>>l: print=>yes>:< l QS l print=>no>:< l l Sample Input 45 54 Sample Output TO (esult us; Program > %-I"O(\I \A(I] using "un#tion> as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/
. DIA[O-AL \A(I] Diagonal \atri.A sYuare number; in#luding '. Mrite nn1: integers. e =irst elements in te matri. *alue o= m and n is 5. Out Sour#e Code 7Qn#lude8stdlo.9 7ln#lude8stdlQb.9 int >#reateBrrayint:/ *oid getQementsint>;lnt:< *oid diagonallementsint>;int:< lnt main: l int >a;n< s#an=>?d;@n:< a6#reateArrayn:< getlementsa.n:< diagonalQementsa;n:< retum O< l int >#reateArrayint n: i Int i;>a< a6Int>:maQlo#nsieo=int::I =ori6'a;lnt n: l int i;0< =orl6'?d.Zai:0:< i l l *oid diagonalQementsint >a;In = int i;0;#6'< =ori6'8666>>:+>ll
l print=>yes>:< c else i print=>no>:2 l l Sample Input 2 4 5 5 4 Sample Output "IO (esult us; Program > DIA[Omatri i# as eros e*eryere oter tan te main diagonal. ntries on te main diagonal may be any a program to =ind eter a gi*en matri is a diagonal matri or not. Input "ormat/ e input #onsists o= integer #orresponds to te number o= rosB#olumns in te matri. e remaining integers #orrespond to te e elements are read in ro ise order; =irst ro =irst; ten se#ond ro and so on. Assume tat te maimum put "ormat/ Print yes i= it is a diagonal matri. Print no i= it is not a diagonal matri. tn: AL \A(I]> as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . %-I"O(\I \A(I] using "un#tion %ni=ormity matri is a matri in i# all te elements in te matn are eiter #ompletely e*en or #ompletely odd Sour#e Code 7ln#lude8stdIo.9 7ln#lude8stdlQb.9 Int >#reateArrayint:< *oid getlementsint>;int:< *oid uni=ormityDlagonaQsint>;Int:1 Int maIn: l Int >a;n< s#an=>?d>;@n:< a6#reateArrayn:< getlementsa;n:< uni=ormityDiagonaIsa.n:< retum '/ l Int >#reateArrayint n: l Int >a;i< a6Int:mallo#nsieotint::1 =orl6'
l *oid getQementsint >Za;lnt n: l int I;0< =orl6'?d>;ai:^::< l l l *oid uni=ormityDiagonalsint a;int n: um l;0;b6'.#6';d;e< =ori6'i66i: 816Zai:l::< lid66e:@@dl6':: print=>no>:< retum< l l l e6d< l =ori6'?dn>;e:< l l >`66>>lQQb66>Z>:: l printt>yes>:< l else l printt>no>:< l l Sample Input 45 54
Sample Output no (esult us; Program > %-I"O(\I \A(I] using "un#tion> as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . \A[IC S%A( A magi# sYuare is an arrangement o= numbers usually integers: in a sYuare grid; ere te numbers in ea# ro; and in ea# #olumn; and te numbers in te =onl*ard and ba#Kard main diagonals; all add up to te same number. Mrite a program to =ind eter a gi*en matri is a magi# sYuare or not. Input "ormat/ e input #onsists o= nFn1: integers. e =irst integer #orresponds to te number o= rosB#olumns in te matri. e remaining integers #orrespond to te elements in te matri. e elements are read in ro ise order; =irst ro =irst; ten se#ond ro and so on. Assume tat te maimum *alue o= m and n is 5. Output "ormat/ Print yes i= it is a magi# sYuare. Print no i= it is not a magi# sYuare. Sour#e Code 7In#lude8stdio.9 7ln#Qude8stdlQb.9 int >#reateArrayint:< *oid getQementsint>;lnt:< *oid magi#SYuareInt>;int:< lnt main: l int >a;n< s#an=>?d>.$+n:< a6#reateArrayn:< getlementsa;n:< magl#SYuarea;n:< retum '< l lnt >#reateArrayint n: l lnt >a;l2 a6Int>:maQQo#nZsieo=int::I =ori6'a;lnt n: l lnt i;0< ='rl6'B89d>;aI:0:< l l l *oid magi#SYuarelnt >a;int n: l int l;0;sum6';sum16';r6O;#6';sum2;sum3;sum4;sum5<
sum6'< =ori6'ai:0:< l sum26sum< l=sum166sum: r< l sum16sum< l l=rl6n+1 @@ suml6': l print=>no>:2 retum< l print=>n>:< sum1 6'< =or06'/08n<0: sum6'< =ori6'sum3 ?dn;sum3:< l=#l6n+1@@suml6': l print=>n'>:/ retum< l sum16'< sum6'< =orl6'/i8ni66l: l sum6sumZai:^:< l l l sum46sum< BBprint=>sum4 B9dn;sum4:< sum6'< sum16'< =orl6'/i8n
l =or06'<08n<0: sum6sumZai:^:< breaK< l sum16sum< l sum56sum< BBprint=>sum5?dn>;sum5:< l=sum466sum5: l=sum266sum3:@@sum366sum4:@@sum266sum4:: l print=>yes>:< l c else l print=>no>:< retum< c l Sample Input 2 4 5 5 4 Sample Output TO (esult us; Program > \A[IC S%A(> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . \aimum lement in an Array using "un#tions Mrite a program to =ind te maimum element in an array. lnput "ormat/ lnput #onsists o= n1 integers. e =irst integer #orresponds to n ; te sie o= te array. e net n integers #orrespond to te elements in te array. Assume tat te maimum *alue o= n is 15. Output "ormat/ (e=er sample output =or details. Sour#e Code 7in#lude8stdio.9 7in#Qude8stdlib.9 int main: i Int a;n;i;ma< s#an=>?d>.@n:I a6int:mallo#nZsieo=lnt::< =orQ6'?d>;ai:< c ma6O< tor6'08nW: i=ma8ai:: l ma.6ai:< c printtB89d is te maimum element in te array>;ma:<
retum '\aimum lement in an Array using "un#tions> as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C T . Sum o= 2 arrays using "un#tions Mrite a program to =ind te sum o= te #orresponding elements in 2 arrays. Input "ormat/ Input #onsists o= 2n1 integers. e =irst integer #orresponds to n ; te sie o= te array. e net n integers #orrespond to te elements in te =irst array. e last n integers #orrespond to te elements in te se#ond array. Assume tat te maimum *alue o= n is 15. Output "ormat/ (e=er sample output =or details Sour#e Code 7ln#lude8stdlo.9 7ln#lude8stdIQb.9 Int #reateArray1lnt:< Int Z#reateArray2lnt:/ *oid readQement1int>;int:/ *oid readlement2int.int:< *oid sumo=Arrayint;int;int:< Int maln: I Int a;n.b< s#an=>?d>.@n:< a6#reateArray1 n:< b6#reateAnay2n:< readlement1a.n:< readlement2b.n:< sumo=Arraya;b;n:/ BBprint=>?dV;#:< retum '< l Int #reateArray1int n: I Int a< a6Int :maQlo#nsieo=Int::< retum a< l Int #reateArray2lnt n: l Int b< b6lnt >:mallo#nsIe'=lnt::< retum b< l *oid readlement1 int a;int n: I Int I< =ori6'?d>;ai:<
l *oid readIement2int b;int n: I Int i< =ori6'?d;bi:< l *oid sumo=Arrayint Za;int b;int n: I Int l;sum6'< =orl6'Bod >;sum:< l l Sample Input s 23$2 1 1 1 1 1 Sample Output 34!&3 (esult us; Program > Sum o= 2 arrays using "un#tions> as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C T . Sum o= 2 arrays using "un#tions Mrite a program to =ind te sum o= te #orresponding elements in 2 arrays. Input "ormat/ Input #onsists o= 2n1 integers. e =irst integer #orresponds to n ; te sie o= te array. e net n integers #orrespond to te elements in te =irst array. e last n integers #orrespond to te elements in te se#ond array. Assume tat te maimum *alue o= n is 15. Output "ormat/ (e=er sample output =or details Sour#e Code 7ln#lude8stdlo.9 7ln#lude8stdIQb.9 Int #reateArray1lnt:< Int Z#reateArray2lnt:/ *oid readQement1int>;int:/ *oid readlement2int.int:< *oid sumo=Arrayint;int;int:< Int maln: I Int a;n.b< s#an=>?d>.@n:< a6#reateArray1 n:< b6#reateAnay2n:< readlement1a.n:< readlement2b.n:< sumo=Arraya;b;n:/ BBprint=>?dV;#:< retum '< l Int #reateArray1int n: I
Int a< a6Int :maQlo#nsieo=Int::< retum a< l Int #reateArray2lnt n: l Int b< b6lnt >:mallo#nsIe'=lnt::< retum b< l *oid readlement1 int a;int n: I Int I< =ori6'?d>;ai:< l *oid readIement2int b;int n: I Int i< =ori6'?d;bi:< l *oid sumo=Arrayint Za;int b;int n: I Int l;sum6'< =orl6'Bod >;sum:< l l Sample Input s 23$2 1 1 1 1 1 Sample Output 34!&3 (esult us; Program > Sum o= 2 arrays using "un#tions> as been su##ess=ully ee#uted
#ourse/ C Wlb0e#t Code/ . Sear#ing an Array using "un#tions Mrite a C program to sear# =or an element >aV in te array. Linear Sear#: Sour#e Code 7ln#lude8stdQo.9 7in#lude8stdlQb.9 Int #reateArrayint:2 *oid readlementlnt ;int:< *oid Arrayint ;int:< Int main: l Int a;n< s#ant>?d>.$+n:< a6#reateArrayn:< readlementa;n:< Arraya;n:< retum '<
l lnt #reateArrayint n: l Int a< a6Int :mallo#nsleo=lnt::< retum a< l *oid readlementint a;int n: lnt i< =orQ6'/i8n?d;ai:< l l *oid Arrayint a.int n: l Int b;l;#6'< BBprint=>b6:< s#an=>?d>.@b:< =ori6'?d is present in te array>;b:/ l else l print=V?d ls not present in te array>.b:< l l Sample Input s 231 Sample Output is present in te array (esult us; Program >Sear#ing an Array using "un#tions> as been su##ess=ully ee#uted
Course/ C 11 Sub0e#t Code/ . -o. o= Distin#t Mrite a program to = o= n1 integers. e in te array. Assume number o= distin#t el Sour#e Code 7in#lude8stdio.9 7ln#lude8stdlQb.9 int #reateArrayint:< *oid readQementlnt ;int
*oid distin#tlementint int main: t lnt a;n< s#an=>?d>.@n:3 a6#reateArrayn:< readQementa;n:< dlstln#tQementa;n:< retum O< l lnt #reateArrayint n: l Int a< a6lnt :mallo#nsleo=Qn retum a< l *oid readlementint a; In Int I< =ori6'?d>.ai:< l l *oid distin#tlementint Za l lnt l.0;b61;d6'/ =ori6'?d>;d:< l Sample Input ! 3452334455 Sample Output ! (esult us; Program > -o. Iements in an unsorted array ind te number o= distin#t elements in a unsorted array. _Do it itout sorting te array^ Input "ormat/ Input #onsists =irst integer #orresponds to n; te number o= elements in te array. e net n integers #orrespond to te elements tat te maimum *alue o= n is 15. Output "ormat/ Output #onsists o= a single integer i# #orresponds to te ements in te array.
:2 rm:< 1::< tn: .int n: o= Distin#t lements in an unsorted array> as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . \atri Sum using "un#tion Mrite a program to =ind te sum o= te elements in te matri. Input "ormat/ e input #onsists o= mFn2: integers. e =irst integer #orresponds to m; te number o= ros in te matri and te se#ond integer #orresponds to n; te number o= #olumns in te matri. e remaining integers #orrespond to te elements in te matri. e elements are read in ro+ise order; =irst ro =irst; ten se#ond ro and so on. Assume tat te maimum *alue o= m and n is 1'. Output "ormat/ (e=er sample output =or details. Sour#e Code 7ln#lude8stdlo.9 7ln#lude8stdlQb.9 lnt >#reateArrayint;Int:< *oid getlementsint>;int;int:< int sumo=Arraysint>.int;int:< lnt maln: lnt >a;ros;#olumns;sum< s#an=>?d>;@ros:< s#an=>?d;@#olumns:< a6#reateArrayros;#oQumns:< getlementsa;ros;#olumns:< sum6sumotArraysa;ros;#olumns:< printt>e sum o= te elements in te matn is ?d>;sum:< retum '< i Int >#reateArrayint ros;int #olumns: l lnt >a;IR a6Int>:mallo#rossleotint::3 =ori6'a;lnt ros;int #olumns: int Q;0< =orl6'?d.ai:^::< : l l lnt sumotArraysint >a;int ros;lnt #olumns: i
lnt i;0;sum6'< =ori6' \atri Sum using "un#tion > as been su##ess=ully ee#uted
Course/ C 11 Sub0e#t Code/ . " Mrite a array som m ele #orr Sou 7ln#l 7ln#l int C *oid int W lnt m 5'$ $6CQ prin l retu l int # a6ln retu i *oid lnt I< BBprin =orQ6 = s#a l l int W
l int i. BBprin Q=a l #< l else b 1r 6 Q&t% i $QH l [I% l el l = % l retu l Sa 5 2 4 1 Sa e (es u ndy ain getl #6=in I 6 pQlIt else I pnn else I Int a< m l n= nd= #f' i $QS l d< i l C m m se et m m m
II & array is \ied. integer element P [S PC ude ude reat get VII int a. pnn n= =# 61: . m : . Wr l l Wr m =# =# ' t>: 3 get tr> > i: =orl6'? eate em dy re at '
>? I as I #tions+Array ype program to =ind te type o= te array using =un#tions. An array is said to be X *enX i= all te elements in te array are e*en. An ome e*en elements (e=er =un#tion spe#i=i#ations =or te =un#tion details e =irst argument #orresponds to te number o= s in te array. e se#ond argument #orresponds to te pointer to an array. e return *alue o= te =un#tion sould be 1 i= te *en. e return *alue o= te =un#tion sould be 2 i= te array is Odd. e return *alue o= te =un#tion sould be 3 i= te array is Input and Output "ormat/ Input #onsists o= n1 integers ere n #orresponds to te number o= elements in te array. e =irst #orresponds to n and te net n integers #orrespond to te elements in te array. Assume tat te maimum number o= s in te array is 2'. (e=er sample input and output =or =ormatting spe#i=i#ations. All tet in bold #orresponds to input and te rest onds to output is said to be XOddX i= all te elements in te array are odd. An array is said to be X\iedX i= it #ontains some odd elements and nt e Code 8StdlO.9 8stdQQb.9 eArrayint:< lementint;int Z:< peint;int Z:< : LC< nter te number o= elements in te arrayn>:< d>.@n:< Arrayn:< entn;a:< P'1$:< >e array is *en>:< 662: >e array is Odd>:< 663: >e array is \ied>:< eArrayint n: maQlo#nsleo=lnt::< Qementint n;int a: nter te elements in te arrayn>:< n;ai:< ypeint n;int a: .b6';d6'< a6?d>;Zai::< 266': ai:BO2661: e Input e Output y is \ied ult Program > "un#tions+Array ype> as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . Compare 2 arrays using "un#tion Mrite a program to =ind eter 2 arrays are te same. Input "ormat/ Input #onsists o= 2n1 integers. e =irst integer #orresponds to X nZX ; te sie o= te array. e net XnX integers #orrespond to te elements in te =irst array. e net XnX integers #orrespond to te elements in te se#ond array.Assume tat te maimum *alue o= n is 15. Output "ormat/ Print yes i= te 2 arrays are te same. Print no i= te 2 arrays are di==erent. Sour#e Code 7ln#lude8stdlo.9 7ln#lude8stdlQb.9 int #reateArrayint:< *oid getlement1 int ;int:< *oid getQement2int ;int:< *oid #e#KArrayint ;int Z;int:< int main: t int a;Zb.n< s#an=>?d>.@n:2 a6#reateArrayn:< b6#reateAnayn:< getQement1an:< getlement2b;n:< #e#KArraya;bn:< retum O< l int >#reateArrayint n: int a< a6int :malQo#nsieo=Int::< retum a< l )Oid getQement1int a;int n: t int I< =orl6'?d>;ai:< l l *oid getQement2int b;int n: int ii =ori6'?d;bi:< l l *oid #e#KArrayint Za;int Zb.int n: int i;#6'< =orQ6'/i8nai6?dn>.ai::< BBprint=>bi6?dn>.>bi::< >Z$i::66Zbi::: i
#< l l l=#66n: t print=>yes>:< l [IS[ t print=>no>:2 l l Sample Input s 2334 23$4 Sample Output S (esult us; Program > Compare 2 arrays using "un#tion> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . -o. o= Distin#t lements in an unsorted array Mrite a program to =ind te number o= distin#t elements in a unsorted array. _Do it itout sorting te array^ Input "ormat/ Input #onsists o= n1 integers. e =irst integer #onesponds to n; te number o= elements in te array. e net n integers #orrespond to te elements in te array. Assume tat te maimum *alue o= n is 15. Output "ormat/ Output #onsists o= a single integer i# #orresponds to te number o= distin#t elements in te array. Sour#e Code 7ln#lude8stdlo.9 7in#Qude8stdllb.9 lnt #reateArrayint:< *oid readlementlnt ;int:< *oid distin#tlementint F;int:< int main: l int a;n< s#an=>?d>.$+n:< a6#reateArrayn:/ readlementa;n:< dlstln#tlementa;n:< retum '< l int >#reateArrayint n: l lnt a< a6lnt :mallo#nsleo=lnt::< retum a< l *oid readlementlnt a;int n: int i< ='ri6'li8n?d;ai:<
i l *oid distin#tlementint Za.int n: l lnt i.0.b61d6'/ =orQ6'/i8nai:6630:@@b661: dE+< b6'/ l l b61 < l print=>?d>;d:< l Sample Input ! 3452334455 Sample Output ! (esult us; Program > -o. o= Distin#t lements in an unsorted array> as been su##ess=ully ee#uted
. Sum o= pos Mrite a progra Sour#e Code 7in#lude8stdio.9 7Qn#lude8stdQQb.9 Int #reateArrayin t *oid getQementin Int sumo=Arrayint Int main: int >a;b.n< s#an=>B89d>.@n:2 a6#reateArrayn:< getQementa;n:< b6sumo=Arraya;n print=>e sum o= retum '/ l Int #reateArrayin l int a< a6lnt :malQo#nZsl retum a< c *oid getQementin Int I.
=ori6'?d>;ai:< l l int sumo=Arrayint i lnt sum6O;i< =orQ6'al:< l l retum sum;b:< tn: eo=int::< t a;int n: $;QIll I1: I siti*e numbers in te array is 1& > Sum o= positi*e numbers using "un#tions> as been su##ess=ully ee#uted
Sub0e#t Code/ . Sum o= e*e Mrite a progra to XnX ; te si Output "ormat Sour#e Code 7in#lude8stdio.9 7ln#lude8stdQQb.9 Int #reateArrayint *oid getQementin lnt sumo=Arrayint int main: l int a;b.nI s#an=>?d>.@n:I a6#reateArrayn:< getQementa;n:<
b6sumo=Arraya;n print=Ve sum o= retum '< : l int Z#reateArrayin l int a< a6lnt :malQo#nZsl retum a< l *oid getQementin t lnt I. =ori6'?d>;ai:/ l c Int sumo=Arraylnt l Int sum6O;i< =orl6';b:< t n: eo=Int::< t t a;int n: a;Qnt n: en numbers In te array is 1 > Sum o= e*en numbers using "un#tions> as been su##ess=ully ee#uted
. Sum o= e*e Mrite a progra Sour#e Code 7Qn#lude8stdlo.9 7in#lude8stdlQb.9 lnt >#reateArrayin t *oid getlementin *oid sumo=Arrayln rm main: t int a;n< s#ant>?d>.@n:< a6#reateArrayn:< getlementa;n:< sumo=Arraya;n:3 retum '< l lnt #reateArrayin t int a< a6lnt :malIo#nsl retum a< l *oid getQementin int i< =orQ6'B89d>;ai:/ l l nt *oid sumo=Arrayi int i;sum16';sum2 =orl6'e sum o= printt>e sum o= l Sample Input 5 23$+1 Sample Outpu e sum o= te e* e sum o= te od (esult us; Program #ourse/ C =ub0e#t Code
m t n n and odd numbers to =ind te sum o= e*en and odd numbers in an array. :/ t;int:< tZ;lnt:< : eotlnt::< t a;int n: a;int n: 6'< :2 :3 te e*en numbers in te array is B89dn>.sum1:< te odd numbers In te array ls ?dV.sum2:/ t en numbers in te array is 1 d numbers in te array ls 2 > Sum o= e*en and odd numbers> as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Stru#turel4 Mrite a program tat uses a stru#ture #alled date tat as it passed to an isLeapear =un#tion to detennine i= te year is a leap year Input and Output "ormat/ ample/ O5BOB1&!$ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude 8stdio.9 stru#t date int day/ Int mont< lnt year< :< int lsLeapearstru#t date d:/ lnt maQn: stru#t date d< BBprint=>nter te date eg/ '5B'B1&!$:/ >:< SC3l1=>BodBBodBB'd>; @d.day; @d.mont; @d.year:< i= lsLeapeard: 66 ': print=>n ?d is not a leap year>; d.year:< else print=>n ?d is a leap year; d.year:/ return '< l Int lsLeapearstru#t date d: i= d.year ? 4 66 ' @@ d.year B89 1'' l6 ': Q_ d.year ? 4'' 66 ': retum 1< else retum O< : Sample Input osroeB1&!$ Sample Output 1&!$ ls not a leap year
(esult us; Program > Stru#turel4 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Stru#ture +1! De=ine a stru#ture date #ontaining tree integers +day;monts and year. Mrite a program using =un#tions to read data; to *alidate te data entered by te user and ten print te date on te s#reen. "or eample;i= you enter 31BB2''! is in*alid as ,une does not as 31 days; similarly i= you enter 25B13B2''' ten it is in*alid mont as mont ends it 121+12. 0an to de#:. e tresold *alue =or year is 3''' In*alid ear:. )alid year/ ''''+2&&& %sing te stru#ture de=inition o= te abo*e program; rite a =un#tion to in#rement tat .\aKe sure tat te in#remented date is a *alid date. \odi=y te abo*e program to add a spe#i=i# number o= days to te gi*en date.Mrite a =un#tion to #ompare to date *ariable. Sour#e Code 7ln#lude8stdio.9 stru#t date I Int day< Int mont< int year< I< int enterdatestru#t date d:< Int #e#K*aIldltyint dd; int mm. int yy:< Int in#rementdatestru#t date d:/ Int madays_12^ 6 N31;2$;31;3';31;3';31;31;3';31;3';31:< int maIn: l stru#t date d< enterdate d:< I Int enterdatestru#t date d: int dd.mm;yy;=Iag6O/ BBprint=>n nter te date / :< SC$II=>BodBBodBBod; @dd;@mm.@yy:< =lag 6 #e#K*aIIditydd;mm;yy:< : d.day 6 ddn ?d+?d+?d>; d.day; d.mont;d.year:/ In#rementdated:< retum '/ I I Int #e#K*alldItyint dd. int mm; int yy: = l=yy92'12: I print=>n In*alid ear:< retum O/ I i=mm81 I: mm912: I print=>n In*alid \ont>:< retum '< I
l=mmI62 as. dd8' 1Q dd9madays_mm+1^:: I print=Vn In*alid Day>:< retum '< I i=mm662: I I=yy?4 66 ' $.@ yy?1'' J6': QQ yyBh4'' 66 ':: madays_1^ 6 2&/ else madays_1^ 6 2$< i=dd8' 1Q dd9ma.days_I^: I print=>n In*alid Date:< retum '< I I retum 1< I Int in#rementdatestru#t date d: I d.day/ i=d.day9madays_d.mont+1^: d.day 6 1< d.montR l=d.mont912: d.mont 6 1< d.year< I I print=>n-e Date6?d+?d+?d>; d.day; d.mont;d.year:< I Sample Input 31B13B1&$& Sample Output In*alid \ont (esult us; Program > Stru#ture +1! > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Stru#tures + 21 Mrite a program to de=ine a union and stru#ture bot a*ing ea#tly te same members. %sing te sieo= operator; print te sie o= stru#ture *ariable a ell as union *ariable and #omment on te result. ip/ De#lare stru#ture it tree integer data members and union it same it integers data members. lnput and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All oat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 stru#t date int day/ int mont< int year< l< union DOU
Int day< lnt mont< lnt year< :< Int main: l stru#t date d1< BBlong unsigned int d1.d2< union DOU d2< Int CR s#an=>?d>;@#:< i=C661 :1 l pririt=>Sie o= stru#ture 6 B9ldn; sleo=d1::< print=>Sie o= union 6 ?Qd>; sieo=d2::< l retum '/ l Sample Input 1 Sample Output Sie o= stru#ture 6 12 Sie o= union 6 4 (esult us; Program >Stru#tures + 21 > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . Stru#tures + 23 De#lare a stru#ture POI-. Input te #o+ordinates o= a point *ariable and determine te Yuadrant in i# it lies. e =olloing table #an be used to determine te Yuadrant uadrant ] 1 Positi*e Positi*e 2 -egati*e Positi*e 3 -egati*e -egati*e 4 Positi*e -egati*e lnput and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output Sour#e Code 7ln#lude8stdlo.9 typede= stru#t l Int num< int deno< c"ra#t< "ra#t sum"ra#t;"ra#t:< int maln: N lnt num1;deno1;num2;deno2< BBprint=>nter =ra#tion 1 / numerator denominator:< s#an=>?dB89d>;@num1 ;@deno1:< BBprint=>nter =ra#tion 2/numerator den'mlnator/V:< s#an=>?d?d>;@num2;@deno2:< "ra#t =16Nnum1; deno1c(esuQt6?dBBad>;result.num;resuQt.deno:< BBdisplay te result retum '< 1 "ra#t sum"ra#t=1; "ra#t =2:
N "ra#t result6N=1.num =2.deno: =2.num =1.deno:; =1.deno =2.denoc< retum result< c Sample Input $5 5 Sample Output (esult6!'B25 (esult us; Program >Stru#tures + 23 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Stru#tures + 3& rite a program to read and display te in=ormation o= all te students in te #lass. Ten edit te details o= i te student and redisplay te entire in=ormation Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All oat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdio.9 7in#lude8strlng.9 int main: stru#t student l int rno< #ar name_2'^< #ar DOU_2'^< Int =ees< :2 stru#t student stud_5O^< int i.n.rolno;nerolno< #ar neDOb_$'^;nename_$'^< BBprlnt=Vnter te number o= students/:< s#an=?dV;@n:< =ori6'n nter te data =or te student ?d/>;i1:< BBprlnt=>n nter te (oll no/>:< s#an=>?d>;@stud_i^.rno:< BBprQnt=>n -ame/>:< s#ant>B89s>.stud_I^.name:/ BBprlnt=>n Course/>:< s#an=>?s>stud_l^.DOU:< Ii print=>n "ees>:< s#an=>?d>;@stud_i^.=ees:< l =ori6'(oll no/B9dn>;stud_i^.rno:< printt-ame/?sn>;stud_i^.name:< print=DOU/?sn>;stud_l^.DOU:/ print="ees/?dn>;studW^.=ees:I c retum '<
l Sample Input 2 11'1 (ames 25de#1&&' 15''' 11'2 Sures '&sep1&$& 3'''' Sample Output (oll no /1 1 '1 -ame/(ames DOU/25de#1&&' "ees/1 5''' (oll no/1 1'2 -ame/Sures DOU/'&sep1&$& "ees/3'''' (esult us; Program > Stru#tures + 3& > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Stru#ture + 43 Mrite a program using a pointer to a stru#ture to initialise te members o= te stru#ture by initialise te *alues o= members in te program itsel= and display te *alues lnput and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 7in#lude8mallo#.9 stru#t student l int rno< #ar name_2O^< #ar #ourse_2'^/ lnt =ees< :2 stru#t student ptr< lnt maln: = int i;n< stru#t student stud16N'1;>(a0>;>PTD>.5''''c/ ptr6@stud1 < print=>DetalQs o= te student>:< print=>ln(oll no/?d>;ptr+9rno:< prlnt=>n-ame/B89s>.ptr+9name:< prlnt=>nCourse/?s>;ptr+9#ourse:< print=>n"ees/?dV;ptr+9=ees:< retum '/ l Sample Input ' Sample Output Details o= te student (oll no/1 -ame/(a0 Course/PTD "ees/5'''' (esult
us; Program > Stru#ture + 43> as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Stru#tures + 44 Mrite a program using an array o= pointers to a stru#ture to read and display te data o= a student. Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All oat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 7ln#lude8mallo#.9 stru#t student l int rno< #ar name_2'^< #ar #ourse_2'^< int =ees< c< stru#t student >ptr_1'^< Int maln: l int l;n< BBprlnt=>nter te number o= students/>:< s#an=>?d>;@n:< =ori6'n nter te data =or te student ?d/>;i1:< BB print=n (oll not>:< s#an=>?d>;@ptr_i^+9rno:< BB prlnl=>n -ame>:< s#an=>?s>.ptr_i^+9name:/ ll prlnt=>.n Course/>:< s#an=>?s>.p=r_i^+9#ourse:< BB prlnt=>n "ees/>:< s#an=>?d>;@ptr_l^+9=ees:< l prlnt=>Details o= te student>:< =ori6'n(oll no/B9d>;ptr_i^+9rno:< prlnt=n-ame/?s>;ptr_Y+9name:< print=>nCourse/?s>;ptr_l^+9#ourse:< print=>n"ees/?d;ptr_i^+9=ees:1 l retum O/ l Sample Input 1 1'1 rames bte# 1''''' Sample Output Details o= te student (oll no/1'1 -amerames Course/bte# "ees/1''''' (esult
us; Program >Stru#tures + 44 > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . Stru#ture 4 Mrite a program tat passes a pointer to a stru#ture to a =un#tion i# displays student =ee #ourse and =ee details lnput and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 7ln#lude8mallo#.9 7in#lude8string.9 stru#t student l lnt rno< #ar name_2'^< #ar #ourse_2'^/ lnt =ees< l< lnt displaystru#t student :< Int main: l stm#t student Zptr< ptr6stru#t student Z:maQlo#sieot stru#t student::< It prlnt=>n nter te data =or te student>:< I= prlnt=n (oll nor:< s#an=>?d>;@ptr+9rno:< I.Bprlnt=>n -ame>:< s#ant>B9s>;ptr+9name:< BBprlnt=n Course:< s#an=>?s>;ptr+9#ourse:I BB print=n "ees:< s#an=>?d>;@ptr+9=ees:< dlsplaylptr:< return '< l lnt displaystru#t student ptr: print=>nDetalls o= student>:< prlnt=>n('ll -umber6?d>;ptr+9rno:< print=>n-ame6?s>;ptr+9name:1 printt>nCourse6?s>.ptr+9#ourse:< pr1nt=>n "ees6?d>;ptr+9tees:< l Sample Input 11''1 ,on Pd 115''' Sample Output Details o= student (oll -umber611''1 -ame6,on Course6Pd "ees6115''' (esult us; Program >Stru#ture 4 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Stru#ture 33 De#lare a stru#ture =ra#tion tat as to =ields numerator and denominator .Create to *ariables and and #ompare tem using =un#tion. (eturn ' it te to *ariable are eYual ;+1 i= te =ra#tion is less tan te se#ond and 1 oterise. ou may #on*ert a =ra#tion into a =loating point number =or your #on*enien#e input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All oat *alues are displayed #orre#t to 2 de#imal pla#es. Ail tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdio.9 stru#t "ra#tion int num< Int deno< l< int get"ra#tlonstru#t "ra#tion =: BBprintt>n nter te numerator and te denominator / >:< s#an=>?d ?d>; @=+9num. @=+9deno:< return '< l int #omparestru#t "ra#tion =1; stru#t "ra#tion Z =2: tloat a;b< a 6 oat:=1+9num:B=t+9deno:< b 6 oat:=2+9num:r=2+9deno:< >ab 66 printt>n ?d I ?d is eYual to ?d I =1+9num. t1+9deno. =2+9num; =2+9den':I else it a+b 9 ': print=>n?dB?d is greater tan BodBBod>. =1 +9num; ti +9deno; =2+9num; t2+ 9den':/ else printt>nVB89d;?d is smaller tan ?dB?d>. =1+9num; =1+9deno. =2+9num; t2+9deno:< retum O/ l int maln: stru#t "ra#tion =1;=2I get"ra#tion@t1:/ get"ra#tion@=2:< #ompare@t1 .@t2:< retum '< l Sample Input 1212 1222 Sample Output 12B12 is greater tan 12B22 (esult us; Program > Stru#ture 33 > as been su##ess=ully ee#uted
Sub0e#t Code/ Course/ C T . Stru#ture 42 Mrite a program ; using a pointer to a stru#ture to initialie te members o= te stru#ture to display te students #ourse registration details ere details o= =irst student initialied in te program and details o=
se#ond student get =rom te user ; ten display te details o= bot student 1 and student 2 Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 7ln#lude8string.9 7in#lude8mallo#.9 stru#t student i lnt rno< #ar name_2'^< #ar #ourse_2'^< int =ees< c/ int main: l stru#t student stud1;stud2;Zptrstudt ;Vptrstud2< ptrstud1 6@stud1 < ptrstud26@stud2/ ptrstud1 +9rno6O1 I str#pyptrstud1 +9name;>(a^>:< str#pyptrstud1+9#ourse;>PTD>:< ptrstud1+9=ees614'''< BBprintt>nter te details o= te se#ond student>:< B1 prlnt=>n nter te (oll no/>:< s#an=>?d>;@ptrstud2+9rno:< 1B prlnt=>n nter te -ame>:< s#an=>?s>;ptrstud2+9name:< BBprlnt=>n nter te Courset:< s#ant>?s>.ptrstud2+9#ourse:< 1B prQnt=>n nter te "eesi:< s#an=>B89d>@ptrstud2+9tees:< BB print=>DetalQs o= te "lrst student>:< prlnt=n(oQl ltORBod>; ptrstud1+9rno:< prlnt=>n-ame/?s>. ptrstud1+9name:< printt>nCourse/?s>; ptrstud1+9#ourse:< prlnt=>n"ees/B9dV; ptrstud1 +9=ees:< BB print=>Details o= te Se#ond student>:< prInt=>n(oQl no/?d>; ptrstud2+9rno:< prlntt>n-ame/?s>; ptrstud2E9name:< prlntt>nCourse/?s>; ptrstud2+9#ourse:/ prlntt>n"ees/?d>; ptrstud2+9tees:< retum '< l Sample Input 12 ram lt 2333 Sample Output (oll no/1 -ame/(a^ Course/PTD "ees /1 4''' (oll no/ 1 2 -ameram Courseilt "ees/2333 (esult us; Program > Stru#ture 42 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Pointer 2 Mrite a program to #ompare to arrays using pointers. Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 int maln: int arr1_1'^; arr2_1O^; i6'; n1; n2; eYual 6 1< BBprint=>nnter te number o= elements in te =irst array/>:< SC$=>Kd. @n1 :1 BBprint=>nnter te elements o= te =irst array/>:< =orl6'?d>. arr1i::< BBprint=>nnter te number o= elements in te se#ond array/>:< s#an=>?d>. @n2:2 BBprint=>nnter te elements o= te se#ond array/>:< =OlZi6'Bed. arr2i::< 66n2: =orl6'nArrays are not eYual>:< else print=>nArrays are eYual:/ retum '/ l Sample Input 5 12345 5 12345 Sample Output Arrays are eYual (esult us; Program > Pointer 2 > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . Pointer 1 Mrite a program to print >Tello Morld> using pointers Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdio.9
Int maIn: l #ar s_^6>TeQQo MorQd>< #ar p< P65G QQepl6': N print=>B89#>.p:< p< c return '/ l Sample Input ' Sample Output Tello Morld (esult us; Program > Pointer 1 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Pointer 3 Mrite a program to subtra#t to double *alues using pointer Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output Sour#e Code 7in#lude8stdio.9 int main: l double d1 6'.d26'.sub;p1 ;p2/ BBprlnt=>nnter 1st number/ >:/ s#an=>B89Q=>;@d1:< BBprint=nnter 2nd number/ >:< s#an=?Q=>;@d2:< p1 6@d1< p26@d2< sub6p1+p2< print=>n Di==eren#e o= ?l= and Bo== is B89Q=>;p1.p2.sub:< return '< c Sample Input 4 5 Sample Output Di==eren#e o= 4.'''''' and 5.'''''' is +1.'''''' (esult us; Program > Pointer 3 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Pointer + 4 Mrite a program to #on*ert 3.14 into its integral eYui*alent using pointer Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest
#orresponds to output. Sour#e Code 7in#lude8stdlo.9 int main: l =loat pi63.14< =loat d/ d6@pi/ int a6d/ print=>?d>;a:< return '/ l Sample Input 3.14 Sample Output 3 (esult us; Program > Pointer + 4 > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . Pointers 5 Mrite a program to =ind smallest o= tree integer *alues using pointers Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All oat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdlo.9 int main: lnt a;b;#;al;b1;#1< BB prlnt=nter te tree integers>:< s#an=>?d ?d ?d;@a;@b;@#:< al6@a< b16@b< #16@#< i=al9b1: N i=al9#1: print=>?d ls largestn>;al:< else prlnt=Bed is largestn>;b1:< c else N i=b19#1: print=>?d is largestn>;b1:< else prlnt=>?d is largestn>.#1:< c return '< l Sample Input 4 s 1 Sample Output
4 is largest (esult us; Program > Pointers 5 > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Pointers Mrite a program to input a #ara#ter and Categorie it as a *oel and #onsonant lnput and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All oat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdlo.9 lnt maln: l #ar #;p< BBprlnttnter a alpabet 1 >:< s#an=>?#>;@#:2 p6@#< i=8p66aQQp66eQQp66iQ Qr96689QlZr966u: print=>e entered alpabet is a *oel>:< else printt>e entered alpabet ls a #onsonant>:< retum '< l Sample Input $ Sample Output e entered alpabet ls a *oel (esult us; Program > Pointers > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Pointer + ! Mrite a program to input 1' *alues in an array. Categorie ea# *alue as positi*e ;negati*e or eYual to ero using pointer. Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdlo.9 int main: l Int a_1'^;Zp< 1B prlnt=nter 1' elements /n>:< lnt i< =ori6'?d>;@a_l^:< P6aI =ori6'nB9d+Positi*e>;p:< else i=Vp8': print=>n?d+-egati*e>;p:/
else print=>n?d6Rero>;Vp:< p< l return '< l Sample Input ' Sample Output ' (esult us; Program > Pointer + ! > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Pointers $ Mrite a program to display te sum and a*erage o= number =rom 1'' to 2'' using array de#laration it pointers. Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All oat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. sum6 and a*erage6. Sour#e Code 7in#lude8stdlo.9 lnt main: i Int a_1''^;p< P63l int sum6'/ int i;s62< lts662: l =ori6' Pointers $ > as been su##ess=ully ee#uted
Sub0e#t Code/
Course/ C T . Pointers + & Mrite a program to input 1' *alues in an array. Categorie ea# *alue as prime or #omposite using pointers. input and Output "ormat (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdlo.9 int main: nt inta_1'^.Zp.i;0.#ou 6'<< BB print=>nnter 1' *alues into te array/ >:< =ori6+O?d>;@a_i^:< c P6a3 =ori6'nB9d is a prime number>;Zp:2 else print=>n?d is a #omposite number;Zp:< p< #ount6'< i return '/ l Sample Input 345!$&1'1112 Sample Output 3 is a prime number 4 is a #omposite number 5 is a prime number is a #omposite number ! is a prime number $ is a #omposite number & is a #omposite number 1' ls a #omposite number 11 ls a prime number 12 ls a #omposite number (esult us; Program > Pointers + & > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . Pointers + 1' Mrite a program to add to integers using =un#tions use #all by address te#niYue o= passing parameters and also illustrate te #on#ept
o= pointer *ariables #an be used to a##ess te strings. Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 lnt addllnt ;lnt :< lnt main: t int a;b;sum< BB prlnt=nter te *alue o= to numbers/>:< s#an=>B9d ?d >;@a.@b:2 sum6add@a.$+b:/ print=>ne sum o= te numbers is ?d>;surn:< print=>nA##essing a string using polnter>:< #ar #_^6>nTell'>< #ar p< P6`< Qlepl6O: N prlnt=>?#>;p:< p< l print=>n>:< return '/ l int addint . int y: int s< s6y< return s< l Sample Input ! Sample Output e sum o= te numbers is 13 A##essing a string using pointer Tello (esult us; Program > Pointers + 1' > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . Pointer + 11 Mrite a program to print >[ood \orning> using Pointers. Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdio.9 lnt maIn: N #ar s_^6>[ood \oming/ #ar p< P65G
QQepl6': N print=>B89#>.p:< p< c return '/ l Sample Input ' Sample Output ' (esult us; Program > Pointer + 11 > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . Pointer + 1& Mrite a =un#tion to #al#ulate roots o= a Yuadrati# eYuation . e =un#tion must a##ept arguments and return result using pointers. Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude 8stdio.9 7ln#Qude 8mat.9 lnt main: l double a; b; #. determinant; root1;roo ; realPart; ImaginaryPart< I2 BB prlnt=nter #oe==i#ients a;b and #/>:< s#an=V?Q= Bel= BoQ=>.@$; @b; @C:< determinant 6 bZb+4aZ#< BB COdltiOlI O real and di==erent "''15 i= determinant 9 ': N BB sYrt: =un#tion retums sYuare root root1 6 +bsYrtdetermlnant::B2a:< root2 6 +trsYrtdeterminant::B2a:< prlnt=>nroot16?.2l= and r'ot26?.2l=>;root1 ;root2:< l BB#ondition =or real and eYual roots else i= determinant 66 O: N root1 6 root2 6 +bB2a:< print=>nroot1 6root26?.2l=<>;root1 :1 c I= I= roots are not real else l realPart 6 +bB2a:< imaglnaryPart 6 sYrt+determinant:B2>a:< prlnt=>nroot16?.2l=?.2QW and ro't26?.2=+?.2=l>. reaQPart. imaginaryParZt; realPart. imaginaryParZt:< c return '/ l Sample Input 1
2 5 Sample Output root16+1.''2.''i and root26+1.''+2.''i (esult us; Program > Pointer + 1& > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Pointer + 2' Mrite a program using pointers to insert a *alue in an array. Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdlo.9 *oid lnsertint arr_^; Int num; int pos; int n: int I/ =ori6Znn< l int main: int i. n; num; pos. arr_1'^< BBprint=>nnter te number o= elements in te array=:< s#an=>?d>. @n:< =ori6'Bed>. @arr_i^:< BBprint=>nnter te number to be inserted=:/ s#an=>?d>. @num:< BBprint=>nnter te position at i# te number as to be addedi:< s#an=>?d>. @pos:< lnsertarr; @num; @pos; @n:< print=>ne array a=ter Insertion o= B89d is/. num:< =ori6'nArr_?d^6?d>;iarr_i^:< retum '< l Sample Input 3 && 1&& 2&& 3&& 1 Sample Output e array a=ter insertion o= 3&& is/ Arr_'^6&& Arr_1^63&& Arr_2^61&& Arr_3^62&& (esult us; Program > Pointer + 2' > as been su##ess=ully ee#uted
#ourse/ C Srb0e#t Code/ . Pointers + 21
Mrite a program using pointers to sear# a *alue =rom an array using pointer Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All oat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7Qn#lude8stdlo.9 int main: int arr_1'^; num. i. n; =ound 6 '; pos 6 +1/ lnt Zpnum6@num< BBprint=>nnter te number o= elements in te array/>:/ s#an=>?d>. @n:< BBprint=>nnter te elements>:< =orl6'?d>; arrl::< BBprint=>nnter te number tat to be sear#ed>:< s#an=>?d>. pnum:< =ori6'n?d is =ound in te array at posItion6?d>;Zpnum; i:< breaK< l l i= lO%nd 66 print=>n?d Does not eist in te array. num:< return '< l Sample Input 3 45 ! as && Sample Output && Does not eist in te array (esult us; Program > Pointers + 21 > as been su##ess=ully ee#uted
#ourse/ C Spb0e#t Code/ . Pointer + 2 Mrite a program to #ompare to arrays using pointers. Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7ln#lude8stdlo.9 int maln: int arr1_1'^; arr2_1O^; i6'; n1; n2; eYual 6 1< BBprint=>nnter te number o= elements in te =irst array/>:< SC$=>Kd. @n1 :1 BBprint=>nnter te elements o= te =irst array/>:< =orl6'?d>. arr1i::< BBprint=>nnter te number o= elements in te se#ond array/>:< s#an=>?d>. @n2:2 BBprint=>nnter te elements o= te se#ond array/>:<
=OlZi6'Bed. arr2i::< 66n2: =orl6'Arrays are not eYual>:< else print=>Arrays are eYual>:/ retum '/ l Sample Input 5 12345 5 54321 Sample Output Arrays are not eYual (esult us; Program > Pointer + 2 > as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . Pointers + 3' Mrite a program i# taKes an input =rom te user and ten #e#Ks eter its a number or a #ara#ter . I= its a #ara#ter ;determine eter it is in upper #ase or loer #ase Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All oat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdio.9 int main: #ar #; po< p# 6 @#< BBprint=>nnter any #ara#ter/>:< s#an=>?#>; po:< l=p# 96A @@ p#86R: print=>%pper #ase #ara#ter as enteredn>:< print=>Loer C$S&6B'C>; po 32:< l Q=>p# 96a @@ Zp#86: print=VL'er #ase #ara#ter as enteredn>:< print=>%pper #ase6?#>; po + 32:< l retum '< l Sample Input s Sample Output
%pper #ase #ara#ter as entered Loer #ase6s (esult us; Program > Pointers + 3' > as been su##ess=ully ee#uted
Course/ C Srb0e#t Code/ . Store and (etrie*e Store and retrie*e elements =rom an array Sour#e Code 7ln#lude 8stdio.9 1m main: l int arr1_25^; I;n< BBprint=>nlnput te number o= elements to store in te array/>:< s#an=>?d>;@n:< ll print=>nlnput ?d number o= elements in te array/>;n:< =ori6'/i8nnQement+?d/;l:< s#ant>?d>;arr1i:< l printt>ne elements you entered are>:< =orl6Onelement+?d/?d>.l;arr1i::< l retum '/ l Sample Input 5 1' 2' 3' 5' 4' Sample Output e elements you entered are/ element+'/1' element+1 /2' element+2/3' element+3/5' element+4/4' (esult us; Program > Store and (etrie*e> as been su##ess=ully ee#uted
#ourse/ C =ub0e#t Code/ . \aimum o= o -umbers using Pointers "ind te maimum number beteen to numbers using pointer Sour#e Code 7In#iude 8stdio.9 7in#lude 8stdIib.9 Int main: int tno;sno;ptr16@tno;ptr26@sno< ll printt>nQnput te =irst number/>:/ SC$=l=>B'd>; ptr1:I BB printt>nlnput te se#ond number/>:< s#an=>B9d>; ptr2:< itptr19ptr2:
N print=>n?d is te maimum number.ptr1:< c else N print=>nB9d ls te maimum number>.>ptr2:< c retum '/ i Sample Input 5 & Sample Output & is te maimum number (esult us; Program >\aimum o= o -umbers using Pointers > as been su##ess=ully ee#uted
Course/ C X<.lb0Cl Code/ . Permutations [enerate permutations o= a gi*en Sour#e Code 7ln#lude 8stdio.9 7in#lude 8string.9 *oid #angePosition#ar #1; #ar #2: #ar tmp< tmp 6 #1< >#1 6 #2/ #2 6 tmp< l *oid #arPermu#ar #i; int stno; int end l int I< it stno 66 endno: print=>n?s>. #t:2 else l =or I 6 stno< i 86 endnOR i: N #angePosItion#tstno: #ti::< #arPermu#t. stno1; endno:< #angePosition#tstno:. #ti::< l l l Int main: #ar str_^6>S(\V< int n 6 strlenstr:< print=>e permutations o= te string a re #arPermustr; O; n+1:< return '< l Sample Input ' Sample Output
' (esult us; Program >Permutations> stri ng -ote/ De#lare #ara#ter array to >S(\> in te program no: I>:< as been su##ess=ully ee#uted
Course/ C Spb0e#t Code/ . Pointers + 3' Mrite a program i# taKes an input =rom te user and ten #e#Ks eter its a number or a #ara#ter . I= its a #ara#ter ;determine eter it is in upper #ase or loer #ase Input and Output "ormat/ (e=er sample input and output =or =ormatting spe#i=i#ation. All oat *alues are displayed #orre#t to 2 de#imal pla#es. All tet in bold #orresponds to input and te rest #orresponds to output. Sour#e Code 7in#lude8stdio.9 int main: #ar #; po< p# 6 @#< BBprint=>nnter any #ara#ter/>:< s#an=>?#>; po:< l=p# 96A @@ p#86R: print=>%pper #ase #ara#ter as enteredn>:< print=>Loer C$S&6B'C>; po 32:< l Q=>p# 96a @@ Zp#86: print=VL'er #ase #ara#ter as enteredn>:< print=>%pper #ase6?#>; po + 32:< l retum '< l Sample Input s Sample Output %pper #ase #ara#ter as entered Loer #ase6s (esult us; Program > Pointers + 3' > as been su##ess=ully ee#uted
Course/ C Wlbie#t Code/ Mrite a program to =or =ormatting spe#i tput. (e=er sample input and output =or =ormatting spe#i=i#ation. All =loat *alues are displayed #orre#t to 2 de#imal #orresponds to ou pla#es. All tet in Sour#e Code 7in#lude8stdlo.9