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

ITP-unit-3 notes

The document provides an overview of arrays in programming, detailing their structure, types, and advantages. It explains how arrays store collections of data of the same type, their memory allocation, and includes examples of one-dimensional and multi-dimensional arrays. Additionally, it covers array operations such as initialization, searching, and calculating sums and averages.

Uploaded by

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

ITP-unit-3 notes

The document provides an overview of arrays in programming, detailing their structure, types, and advantages. It explains how arrays store collections of data of the same type, their memory allocation, and includes examples of one-dimensional and multi-dimensional arrays. Additionally, it covers array operations such as initialization, searching, and calculating sums and averages.

Uploaded by

nagas2820
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 32
Arrays c Array in a Collection of variables belongings to dhe dame data type You Can store qroup of data of Aame data \ype im an array. oF i = Hina group of weloted idlata item, that Share a Commm Name. A particulay value Tn an away is identified lubing ity index numbers o+ Subactipt sum bey Sgetans * data tape “awry name Csi2e]; + Each ‘element of owvay ih of Sane dota typevand Covvies the same Aize. fe, int = 2 byte « Elements of the array ane stored at contiguous _ memory Locations where .the pirat element 74 “Atoied ot the &mmautlert memory Location. * Elements of the away con be” endl oeevied. Advantages »: ae i dis f | Multiple alicnent ‘ate Abrved “addi, o Stogle untt, ed: Enables user to develop Concshe and efficient Prog ‘ Searching in fast belt? ot the elements ase Aloved im a Sequence. Br Single name tw 2 Bethe: abilily of @ we “0 to tefer 4, e ov Yepraent a Collection of tlewe ; | the Hem number, an them by Spectfing \ Pisedverntag ens a hae ae Fined size: whatever Size) © oo time of declaration 6} at ae ed exceed the Ltmit- Declaration of Aay 2 Dataty pe Aevag-name Cawag.- stzei}s Ex? fot age Cs] ; “TH declarer Sage? asian array domtain a, Maxi mun ob 5 integer _ Constants. Initialization Sh fovea Data. type day =Name Theray vetze] = (vara; uate in Ex: int age ls) =fo,1, ah Fon I Motes : ot index 60 Subscript a int als]; Ree seks ALe] =10 -acyt—20__| : : “olz]| 30 * 4 2G) J na a ats]| Go ata] +30 och 50 a(sJ=ho aryg= 50 ‘ Tepruent a Set op number by an array it Con be oleclared ay intaCsJ; Netet 76 _ ater N elementa, in array, tonge how 26 eee S Typed of Arrays + , one dimensional Array g, TWO dimemimonal frrey 3. Three, dimensional Peeve or mull derdentional Reeraug - pone dimentional foey $ pone dimentionall Dray in C Contato Series of elements of the tame dotaty pe - 1 The elements are Zero -indened , rncaning the firat element 7 iH Position or index 0, and the fast element Kt Poxition oF” index Comey Stze) -1- — one dienenatonal initialization in done Ta 2 wags. i Compile lime inibate atten a. Run - Lime Titalt zation Progra $ Sequential acces uring fox Loop Ceomnpile diene initialization Tone dimensional ovay J ttinclude Abinelude Lceontoch> S main('') int af5J= {10,201 36, 40, af; int 5 Clrsex€ )5 i ave") 5 Print-t( “elements o>} | for (ino, 145 7 itt) { rae Pinte (Sd ", ACID); J op: gelch( 5 Elements of array gy 5 to 20 30 Go Sy Notes The output Compile tire, initialeza Hen Prrgratn will mat change -duatng, dipgerent Xe, Ob Pryam. Program? Run- tree wikial? zation : Eon es oy KER even im the given ayeoy- ' - ci op: emer 5 clement i Hinclude Int main ( ) t Int marks Cio] , 7,05 Severs Float Avg Suro; Print (“Enter number of ‘element + ") 3 Scot ("Ped") wns for (iso; F205 i++) ae Print f (“enter valuei") 5 cae Cry yemmarka Ci); : ; Sur =05 for (i=0; tens i++) t Sume= oul ES EIYS 4 Avg = Sum] a5 Prinkt ("sum 15 2", Suen) 5 Print (* avg is Ff", Avg 3: getch C33 5 Pt Emer number of elements ¢ 2 Entey values 12, 13 Sum = 1T Avg = 15-40 Is 21 lo * Program to find Suen of ove nwenbers ino qven amay. Ab include 2éLdiohy Minclude Ztonio. hz Void marn( ) t int alto], Tym, Sum +05 clisex( 5 ra : : , Print (» Enter the sizé Of ong + i Stanf Cd" un); : Print #( ‘Enter the. elements of,0reg * 5 fox ( §:051255 144) Scant ( “Ad, Ka ci); et (hoe; 25 5 v4) if (al A%2==0) _ Sum = Su + al i]s ; 5 ' re 4 . Priot-f ( “olal sumn’ oly evers‘nummbey= 7d" Sue getch (5 ; hcpuh Enter the Size of axvey 15 Enter the element’ vob amey* 12345) vA ‘Total Suen of even numbers? 6 Fes eid ee bate * peg (® print Ake posctien of favgek and f aller of numbers Laing eenag. : fkirclude Lstdio-h> ypinclude 4 Conio, h> yoid main ( ) int 0,7, aCe] 5 int small, big ,pos=0, POSL +97 clyscrl 5 print? Center mo of elements in away") 5 - sant (“ch ", un); Print (“Enter the elements of array 2); for Cis05 fen zi44) < scant ("Yoda ',¢aCi))5 o big 2alCoj; a small =a lols c\(pis ‘ fot (F215 tem S744) , 3 t if (act}>brg) big ail: poste ts # ( aCi] small) Print £ (“dig = fed \ big) ‘ - pant t (" position big ne= tod Ini pos ay Oe OR gee ee Sane eas ey ON yt eenall)S e ap Senall NOE Print £ e “positions ave " pos) 3 getch ( i J Outputs enter no of elements in array ? 5 Enter the elements opaney t 2 beso, O19 big =9 Position of big no =4 Small = 0 Position of. small no =2 iw Develop a program to find the average of Smallest and Lagert (big) in a given arrag- Float Avg Note: add in akove pepe Avg = (srnatl + big/>; : Paint? (“avg of smallest x biggest = p4 ag) Develop a pagan +0 search Key element: im the gwen list of array. (Sinear — HFinclude void main¢ ) : ; L 5 int aL 50] , 7) key, 3 clscey C95; Print #( “Enter tre no of cements é oney * 3 Scanf (*¥. a 7 BN YPN = pid print? es Enter the eletneiity Psp ye) , fos (i205 1455 i494) f Scanf ("%d", Kalil); print # ("Eenter the Key element") 5 scant ("Ye A" wkey) 5 for (i =05 i256 5 i+) ¢ if (acy = = key) Print F (Yod is present at Location=7, key jet) break 2 4 a if (izen) Prt (“od mot present tn the array ", key) > , getch (5 D oukput 3 Enter xb of elements of anay 25 | Enter the elements of coeray 2 “s 71490 Egntey the key element + 0 S190 is present at Location = 5 I pF vie a program “find second heghest and Srootlang muenber in the given anny i HFinctude Zsldvoh> tinclude ¢eonio- h7 int main ( ) { int also), ni, 53 Clrsex 5 +6: 5 Bint? (ease the number of element! 72 © Stank ("%_q", Un) 5 : 3 Pinkf (“enter the array elernent> © /7 fot (1205120 5144) Stan (a wold); for (icy 5 120 itt) jot temp 5 . fot (ett 3320 989) 4. bby # (atid vaC3d) £ ' temp solids print (the seumA Snallast clement is 4,22) park + Cw); . “a Pri? ("the Second longest: clement 3s Joc a ans | 4c keh C4 gekurn OF 5 output 3 Enter the number of elererte5 Enter the array elements> 2.6 4°50 “The Setond Srrallert element is 2 “the Second largest elementis & are to Calculate the sum and ehivte a ¢ prq af kde. ony y difpevence ob tus dEinclude teinclude 2 Contto-h> int main ) & : int x) Cr @CIOJ Cio] , plto} Cig, SeaLto] Cio], dee LeILe, 155 2-dtmensi clyscy( ) 5 Paint (“Enter the number of ‘yous Ds Stam (% Yoh", 213 : Pmt (“Enter the number of Columns: Ds Scanf (%d "wey; ; - (itate ts In Entey elements of Ast rratwixs\n") 5 ex (ico p ta05 t+) 4 ° acts i bo (G20 53€5 54+) i f Sant (%y4", wali CI); 5 Print ("enter elements of 2% Fo (j20 i215 i+) For (j=oj)ecsitt) £ ; scant (“hd wbCiJCID)3 d natit a\n'); I) adding tusv mactvces fox (4205 1247, itt) C oe for G=0 53465 jet) t . TJ = Sumi] a LCI + bOI 5 5 i; M printing the yesult (sur) pantt (\n Sum of #9? enabices 2 \0")5 fos (i2051245 Itt) ie on fot G 295 jecyitt) font (epedlt”, sun CIC); j : 3 hog pant G'w')5 5 4 J pee en “pratt (19 difference of tun mocks eg re ws for (i205 1245 itt) a for (52055467 I**) C dite COILS = aia) z BLIILA; 5 5 J pemting the resuft (deer) for Geos, Tee 5744 ) ¢ for (j-0 ; ec; jrt) e PrinkF(s ag\t", dive CiJEU]) 5 3 : Punt C10") 3 gerch € Wy veturn 0~, 5 oukput = : A ie F i Enter the number of vows 22 Enter the ruamber of Columns 32 Enter elements of 1st maker: 2 6 & 10 : Enter elements of ard meetin 2 4. 6 g Sar of two matrices: 4 lo ty 18 Ditgerence of two makes: One. 20°02 CO ‘ w Develop & C prgrarn -o multiply Easy CRAs Hy? Madrce, Wrnclude zstdiosh> Hh include <¢conio. hr Voicl maint ) int aCioj Cog, bUelfieJ , c Cio [10J-, int UI, k, et, N1,m2,025 4 Clysex¢ y rey Prints “enter no-0f rows and Columns for matsx Az"), Slam# (pd nd Bt, und )5 Pantt (sent no.of waus and columns So mati B:") Stoonf (* “dh d" wea, 992)>, if (4! 2m2) eae PAD Co Mutt pl etion is not possi ble)», else G Printt Center matar A value + W4 fos (i205 izm4 yitt) For (20; jJent 5 te Cn oe Sent (=%d") waltI CI); ‘i : : oe 3 : Paint (“Enter matit Bvalue 2 \n")3 For (iso jizmr5i¢e) - ‘ for (5-055 42 5 jrt) G start ("fd ub CLID)5 5 for(iz04 ic mi5 itt) for (20 5j202 5j4+t) < : cCijli] =o, Fox(k=0;k2n15 kt +) + CCSCIE ¢ CEG ]+ (acid * bpescay) 5 5 y Pant t (" Multipleation iss \n")s for Cizoy Te et pitt) fos (j-05 jz n25jtt) { ‘ Pott (« ed *, cCiIL Gs Pantt (“\0")5 vhad ae getch (3 e alex AT2 2 rotix Bs 2 2 Enter mo.of vows and Columns ‘Main ) t . int af3j03J,7,35 , . " Paint £ (Senter elements 9 @ray); for (i205 7235i+*) { for (j=05 j23554*) { : Seanf ("Yd & aliiliJ); 7 . Prints (sclements of aay ave )} fo (feo 5 i235 444) { fer (52055635 jtt) Pant¥CZA\U" ACC ID)s 4. Pantt (-\n*), 2 aj oulpul> eter elements of arrays) 23456 7 8 Ue elements of away are i 2 3 q 5:6 qyrt4 Stxings: povay of Character ox Collection of Chavacters in Called a skiing . A sing always yecoguized in double quotes. A stving is terminated by Qa null chayacters 10: ov Z A String is a Sequence of chavacteya’ terminakes with o null charackey Syntax: Chay Sty- name [size] ' in the above syntax sty-name. is any mame given to the Stxing variable and size is ured to define Leng th of the Shing. ‘ey The number 6 characters String will Stove: Declaration : : chat Stoing - Name [50 5:/ String of Length 50 fi : characte v4. i tialigation: ; ) using Single chavacter Combent. rp User musk place Char aio] =f H',%e', Wi, 50% 1 MOS walt chavacker Fee TE LRT LD) "interac 1k marks end of Shing. b) Using sting Congcent. chay aLwJ = “Hello” 5 tered ‘\o’ is aqulomatiolly S fete (eteleiel es” y | "0 dig, play Stvingh we fan we oS o foveal ‘Specibiey Program: HEinclude 2stolio h> ™main( ) t " char a [ie] = “Hello” 5 clyser( 5 aon Cates string is 75", a); getch y; ar ' Output: Given stving is Hello String ‘Heend ling Functiom in C2 : Co Language provides sua “Het ob Sting Renton for manipulating the shing. To use there functions we mut include * shang. h * header ‘file. of thae functors Ahould be covtten, fr; Lower care roc ACEC Sting fanchors are 0 4. SKY Lor ) re, - Strlen() 2 stecpy ) 3. strcat( ) 4. sevemp() o Becev Ch err ge gurape OF" a hit 4 adipose is clade lie Os Se - sett getlenot This function giver the Length of the sting. joer TO Of characlers. in a shang: syntax 2 Stvlen Cstaing name); peg? le teclude cstaio.h> (12th pre-lefpned func) AF include Z sling. h> Main ( ) Char a(3eJ= “Hello 5 int Ly Le strlen (a) 5 Parott( “Leng th of the Sting =,“ad eo, getch ( )5 3 oalp Leng th of the stvog aS Write a peqrano 4px Aength of a given sting wing pre-define function. : Atinclude Zstdio.h> imt main( ) ‘int j, ten=o5 Char sty [100]; Pantf (<\n Enter the sting:") 5 Stant (“a5 + y stv) 5 for (i=0; stvLi |= =o; T++) Lend, oe Patt Chength oy the Sting Sed “behys! : Tt Enter the Stving + Tobd Length of the Sting = 4 Di as as without i ' f k t ft 2 Strepyty: This function is used for et One Shing into another Sting - whe 7 °F He dertination Shing must be qe es to the Source Sting: Symtoxs Stycpy ( destination Sting , Source sbing ) 5 Pp mS Te aEtnclade’ Hinclude gstying. h7 main ( ) Chay a (50), b£5°5 Clysart) 5 Punt? (“Enter a source Sting : oe Scant C*ans s a); Skeepy (ba), Print (« Copied Sting 263 "b)5 gekch() 5 4 ee Entey a Source Sting; Hello Copied String = Hello - Ulvite ac pegan to ony one shiny - comothey Shing without using Lilnony function. Hinclude Zsidio-h> ote: include: Z Conio- hy mam ) chat Stes[ 20), stv afro} 5 ntet 5 PHOLEC" Enter Source an: ", "gets Csty4); fos (iso; styalijl =‘\0/; itt) Ste2[i] estvia Li]; Str2L1] = ‘0 PHOLE (Yn Copied Sting 15= hs stra); output . Enter Source Sting + Ramu coped Sting iS = Ramu 3.Stvcat Cs This ts wed tor Gombintog concatemerting usd stings. ‘ + The Leng th of detination | mnust be ue than Source sting - ‘The wesultant conceal enacting orang cal be 7 Source sting: Syntax Strat (sting 4, Sting 23 Prqvam? Cwith pre-defined function ) AFinclude 2 Stelio. h> te include Z Gono. h> | A oe include 4 stviog. h> wmain( ) | chav ase] = “Hello”s PM ‘ | char 6 [50} = “@ood enorsing” 5 : ce | clyser (30% ‘ i stveat (a,b); | PRE (\ comcatenating String is = %5 ',0); | | Telehl 5 ait: ; : ing 15 = Hello Good MOC og Snes Concatenating Axng is 2 ‘ te tu Shings halve a pogrom 4a “Concalenn Lai thou taing. presdepived -fubcton (Sibi juny AFinclude £stdio.h» A include Leonia hy Main ( ) Chav SiC] , 62 [tJ int hength=0,7,j; Deere |" enter frost sting: ')y Sets (s1) 5 Pant Centey Second skewing") 5 gets (s2), for Cizo 5 S405) - ‘No’ 5 r44) Aength = engine 1 5 for (i Length 14°03 sepajy =o ier jet $10iJ -s2 04; . S1Lij 97 Print f(s 1 Ruuttant Sting is 18", s4)5 Output = : Enter the fivst Shing 5 Veda Enter Second Sting: Shanvt Resultant Sting is Vedashanyt p-strempl ys, TAGS function Compares | tus sbangs- | jE velurnr Abe ASCH] dipperence of the ‘first tum non - malching chavackers tm bol the slings: gyntax® Stremp Cstving 4, slving 2)5 conditions IF Sting 4 == sling 2 it relurns B If Shing 1 > Stang 2 Th velurns tye value If String 1 < string2 Tt veturns —ve value. Noles ASCH value aoz Qt — 122 AvZz 65 —7 40 Ss oi St pe Raro Ram g=qt pate? Se sz Ron Ram Az 65 Rar a=4t ° +32 232. Returns O Returns ve Return —VE Progxarn: st indude 2stdio.h> main C ) { chay afsoJ, b £50J5 int c; Print (“Enter 2Stving Ws aia) ASHE", O, b)5 = Styemp (a, b); if (€==5) prot ("25 "is. eral " Qyb)5 elseif’ (c¥0) » Puntt (“5 is greater than 7-8/0, 0 7 elseif (€ 49 es Paintt (ys is bes thar Tsar Mat? J 2iPs Enter 2 Stvings + “These a 15 gueatey than b Thety 4 ithout Wrtle a program to Corn 2 sheng. uring pre-define function’ 4E include te melude Z conio-h7 Void main( ) t char s1[s0J , s2050J5 intuifets 3 Pantt ("Enter frat Shing: ")5 gets (s1); = Pantt (“Enter Seeand string? "5 gets (s2); for (i=; stCiJ L=*\0'5 i++) £ if (st Cid t= s2LiJ) t i008 _ f=t5 at ys eo ee ue iy 3.8 Pantt(" stings 9 are’ not ‘ala "); etse printf (* Tee are same »; 3 output+ Entet icat Sting 2 Hello Enter Second string : Hello Stings are Same. peiueye )2 This jencton is ured for Teversing a sting: Symon? Strrev (sting DF pegans include at include ctinclude Seonto: h> Void main ) Ges Chay sty (20) 5 ee ge i a Lee int Length= 0,15 Prntt (Enter a sting : He Jeks (sty )s Wr Cizoy styriJ = "\ Aength t +5 = Cis hengih-2 51> oat Manteno! eri), Oubput: Entey a Sting: Shourya ay rus hs 6. stvupr (32 Ibis wed 4 comvert Lower cae Characters of the shang to Upper Case Synton: Strupy ( sting) 5 HE include £stdioh> 4b include Asbring b> main () 6k ¢ chor S[i0J; Pratt (* Enter a. shang: Ds gets (s)3 Stvupss)5 pantf Cm Ruultant biog is ‘hs Ws)s ‘t Program: getchl)s ped: eleyiy a Enter a sting, shanvi Resultant Stingis SHAN oe yecte. @ PoTvern to Convert Lower Care characters ® oy the slang lo Upper Cae usithout hong pre~ define june bom rHinclude 28tdio.h> maint ) t Chay $ Cio), io 15) © Prat f Center a strings"), getals)s for (ino; SCITL=\0' 5744) t . if (aCi) >=97 wu aCijz=t22) c . OCtJ= aCij-325 5 alij=‘\o’; Pant ("the resultant string is hg” s); 4 ‘ eS 8)5 ute Enter a Sting: vam ‘The resultant stving. is RAM + Sty hor CI Ibis wed 40 Convert upper care Chayaolerr of the sting to Lower Care. Syntexs Shy Lut (sting) ; | Papa: | ctinclude ¢stdioh> H include < sling: h? main ¢ ) Char $Li0J3 Pott (« Enter a. stang:") 5 | gets (s)5 Sty lw (S)3 PROLF (in Resultant orn is 15", 8)5 Jetch( Js 3g Entey a stving = HASINI Resultant sting is “hosiat are Chavockers of x0 ext: Upper & lbite a prgram to Conver ea oth tthe Shing te ower Care wi thouk way AFinclude © thinclude main ( ) € chor SCI] 5 int i; Saas Print (“Enter o Shing : "5 gets (s); for (i205 SCTIL V0 5 ae 4) £ ; if (stid>e 65 Uy site a8 Sctij= slijtaz5 ered BCiJ =‘\0'5 Ye pantt C° Rerultant Stang is 45", 8); getch C ) 5 j output? enter & Sbi0g + SHouR YA Raultant sting is Shourya Is palind vorne oY mol. | | | | | | goevelop & progrann to cheek whethey the given sting dbinclude . ct include main ( ) aC Chay S [10] , terop [10] 5 Int 1,5, Lens 0, flag = 0; Patt (“Enter o stwng:") +, gets (s)5 for (i=05SLiTf 2%fo"s i+ +) dentt? for (ico, je ten-13 tej 3744, 4-2) (sci! seq) { flag=4 ; break ; '# (flag = =1) RRL ( Nk’ else Prt Copa palicdvome sta og); nd me Sting a) Output + Enter a shing: wow Palindiome string.

You might also like