0% found this document useful (0 votes)
30 views24 pages

Unit-3-Problem Solving Using C (Mca-112)

Unit-3-Problem Solving Using C pdf

Uploaded by

Shubham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
30 views24 pages

Unit-3-Problem Solving Using C (Mca-112)

Unit-3-Problem Solving Using C pdf

Uploaded by

Shubham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 24
PROBLEM SOLVING SING C MICA | ‘rays ay scion ahd premtin, Dati om-imesoal ay ‘ekernie raja sur Teedieataed say Maier ‘otters: natant © opr Pome pe deviation od ‘Sgimeat mer arma Cally recs, Pain ors oxo saga uters Perino: Pur per, ra os [igre tig sng, cong ig ements Ay of ne, ‘ose stig fc, Sting unto Arrays: Araye snd ta mcr rt can sor dee essere ‘dont ta sae pe. An aay resto er arora bd ‘nore aed tk an ay st acoeion vrais de ne pe Ina decoy nda varie, sh 09 nyo nba. te aunb. ‘Suds ove ay vl ch arene and wa arses aed ‘inbonbjerepenoninssavorcies opaste sonar nan ay wooed “A areye cna of consti mama enn. Te net aes creapins he (etoemer ana tvenighn sar Oe ene | i Array size-5 C Arrays ‘Av aay avariatio hat can sore mp vaio. Fr exam, you wat © ‘sore 100 ages you can reat an aay fore Types: Numeric Arrays Character Aray Prope ot Arey es ‘Advantage of C Array 1) ne ptm: at cae he act et 43) fae oertng To ut tee be aay ed fo ne ey. Rann Ace: cn tay smart anny ing ey. Disadvantage of © Array Initializing Arrays, You anise an ray intra on rer le tema owe = “runt of als tne rca} cera tn inert enanetteant (tae aceite syste sate Soca yore ey arriba wou oh em nn sc oul cet cy a ee aay a you dn rcs ears along ‘boonies asa seston ‘eof en ata all bo ur to Wf aay rarus 1 Shown ow a Soe ‘overstayed! abe = How to initialize an array? his posable inae an aay dung dedaraten. For ame, "Yu can eo inizn an aa he is. ere, we haven spot he see, However, he compe rows iz i 5 ae are inng wn leer dtl ai) mat) ma mk ole reve seo cae mest ta eu et mio) ee et mest ta eu tet ‘Accessing Array Elements ‘You cn ces laments nay by es. ‘suppose you secteed an ary wit a above. The tat ements wee. he ‘secon laments and oon. rac] aii] mat) ma) ma Fow hoynowes: + Ary have 0 30h tine, not ni exampl, ie) thet element + fe se of n ays 1 ass te ast lemons, the = Index usd. Ins ‘ramps, nov + Suppose he startng odes of mia 621208 Then, te sates the rs ibe 21244 Sie ess fm] wibe 24284 and s0 “Tie became esas fa at 4 Dyes, ‘Change Value of Array elements =a ‘a Samar s zest naar te aray nana THs Is done yaa e sexo Meester be aac ae nen Poreetae® = bearer): ‘Thm ve steel tk he 1 amar tome any an ang ih vata ‘uy ones lurg unis Shs au 9 un sit ee soe mamand ‘Shenae taarnen aunt ane cena gs Input and Output Array Elements ‘ers bow you can ko put rom th usar and store in an aay elon cata tas ‘e's bow you can pee an nel leant on ary. cea, casts foe at 28 1 1 (eet ot gy te an rte thetarmnQl)'=adhor, $y al bs ‘When bom de scampi neni procs te lowe = nemecla) eee BSS} t Set Example 1: Array Inpu/Output se) Example 2: Calculate Average ees ) up ‘Access elements out of ts bound!RangelLimiSize ‘Suppose you ocradan aay of 10 leant. Less, sae cue ‘You can acts he ay leant tr a(t 1 tre) ‘No lt Sy # yu ty to aos tere 2}. Tho loon rot avaable. Thi ‘may caus unexoced opt (unrest behav. Sometimes you mig go an ‘or and some ter ene your program ay un crrety ene, you sous never acess ements fan aay ote os tour. C Array - Memory representation Gee Te Te Te 17) ‘Two Dimensional Array in C Pepe gianna Seco eee ES SS Declaration of two dimensional Array in © 1 enoe ery nantes: onset fetming ers tenses: Initialization of 2D Array in C See Skea tas atts aye een (Gnbe Scred and ees neo a Int arb 82 9,234.88, “Two-dimensional aay example in C ‘nema tt, tar] = eo 2) { Multidimensional arrays. (C20 array example: Storing elements in a mati and printing i | Caray ox ‘nti mtv, you tamed out anays, These ray ate led ane mesial nays. Inte nest toa, you wile aout muicensional anys (ary fan aaa. nC powering you can rate an aay of erays. These aay ate known a ‘nidimensiona aay For eae, oe te: re, a mersoal (29) ray Te aay ean ols 2 elements. Yeuean ‘te he aay 233 able wth 3 ons and enh wha colar 26 pet: ene steray een sino at sane sory any se MARIE IT 201 ‘Sindy, you cn deca tee dimensional (2 any. or expe, aoe HN ere a ary can ls 2 element Initializing a multidimensional array ‘ee shou you esa tare no-dersional and eedinensina ara}s Iniiatzation of a 24 array sat ata 36 oh 8 90 sat 8) = (0, 95 4h 68 895 Iniitzation of 34 array ‘You canine tee dmanseral aay simi way ke 3 0 mensional ary. Hers an exam 29, 838,829, ‘Example 1: Two-dimensional array to store and print values 11 promt retrain of ten of ek a pay for ie $053 08) : ay Be 3 teat ouput Ruegeruwreeaye ‘Example 2: Sum of two matrices ita fs 1}, WT ease, 1 tie ot ng mnt oe recs ans“ 62,3635 Rig tag tg ite Peas “or tim joa) Sears owen tt 1 ating creping set of er sts) = A13 SE fon tat $05 462 “tn ire Seared iste, AID , [Example 3: Throe-dimensional array t 1 rang an pre ow see = Passing Arrays as Function Arguments in C Way.2 Feo pray a Say Way. Example ow, crite fog fret,wioh tas ow a8 on IRE ary th ‘robo’ suerte tel psted eget Bums he hwree HO ‘Miners passes ea aon Geen SP Coo, 2 ‘When esto Gang pera mas au along eall= ‘ju et sn et of te ay eoaet man aaa cin a errs ‘rons ora bands Svcs» oma rants Passing array to function in C programming with example us tke varies, ray can aloe paseo a funciona an argent athe [psn we wileam ow opoas he any 9 neon eg eu by sme ana ‘Sones matode. ‘Tounductane tis guido, you shou have the browedg flowing © Progarmeg apes + coAnay 2 Eical t ateo 3 Reaimest erences Passing array to function using call by value method ‘Awe aot know nists of fresnel ne acl parame ped tha ‘rrateuamee rth Bassing array to function using call by reference ven te pas he assaf aye cling a uncon hen hi ales ‘erat cl by eeteres, Wher we sus saan an acre aro” ‘Stelraton chou haw o porate parame io fos te panosd oes. os oy Oupue How to pass an entire array to a function as an argument? ‘n%0 above ramp. we have puso he asso each ray samen no by {pete ofernpn¢ Howes yuan apts ene ayes han ‘es: Tho rey rae ta to astoso itlomort that aay. For oxo {ity rae een yea ay a at eget ote Bar Passing Multidimensional Arrays to a Function ‘Topast mutismensorl aay to a ineton, ony he naa lhe ay pazseso he antonio ore crensiona ny). ‘Example 3: Passing two-dimensional arays om * t i "Note: prograaning you can pss ares once, howo¥er, you cant Return array from function in C Hye wt an aay tomato, you waste w dace a lectern Tron rans ponte snowy mea state date(s When abo Gang pera mas au along eall= Sng ron nig ies ees in enn ta Pas C- Strings and String functions with examples ‘Stings an array of characters is ade, weleun howe dec stings. how Sonat Stn Cogan andtow sine pclae ra hanang We wl se nono compa to stings, cance sings. copy oe ng ‘rahe &pestarmonsu anemanulton eneretans We caper ‘oeatoe cang he pre-dinad ncn arg hearer Webco oe ‘tooo sing hineorayou mus ne stinghtloinyou'C program String Declaration ‘String Declaration 1D ehar si, "B,C, Ts, 0K, 2) char ste[] “ABCD % 10" would automatically Inserted a the end in thie ype of declaration wave Ju fe |r fa] el we at Manod2: The above sing can also be defined as — er ation roa Inthe above ecranon NULL characte 0) tcracaly be need th er ome ang “Secrets he ec he ia. Wis ao elated a Stn emit & Nal Susacer ‘String 1/0 in C programming 1) pea and sean 2) puts and gets Syma of sbowe Sanctions - Asonne srg es sel rin 9, ser), tse); 95 not requiee here anit, dat) ett; “965 not require Read & write Strings in C using Printf() and Scanf() functions Gettcenel a Out te soma poate i used or tings pout Read & Write Strings n C using gets() and puts() functions ‘heater ar cee C- String functions ‘Cargo emo age nto et man noms aes = 30, Funeson& Purpose *sepye2 Cope tng 2 sg sean, 2), Corcnrate sg? oa ewe gst riot nent get gt srt, ‘Reuema Ost anda ae sang a han ste psn O82 sata: Rouen pir whe et aero ng ni [vice Winds our dhe leap f= ring Ser eo a ing lowers [irr convert 8 ng fick appends one rng the cod of sober Cia Wppends fet characters of sing the en of spy - Use it for Copying string nt aedbee Stacy copies firm caracters of one oring ite another cmp! _Reomparcs mo sings mithoo regard to nse (acne that as Reson ignores eae) Sse Tecompares tw strings without regard wo ease (eden to reps) Seicnp ecompares fst characters of wo sings, eat Srp= Used for Duplicating sting Schr Finds out ft occurence of sven character i ring Secs “Winds oat nt occurrence of ive character in string sset Teta characters of sing oa give charseter [rece ~Mcts stu characers fs sage even character Siow de Reverses sting CString function - strlen ‘its tier unigod eho [rare be ngh oe Sng wna nding od charac (arming char ” example of sen SA ee Oupue ‘Sten ure auth lng ho sting sre nary bawever slo eur ho ‘Gil blocateduze exon ote aay. So crab ve exam ah ‘Ron loning otomers woul um ha blo vals. en ena vate 12 ‘inti reulsroum ae 20 a8 the aay ie 20600 statement a man Sireson CString function -strnten ae ‘Set occas vored stan ‘et opine hata tee as ne vate secede masen Inaniman ong ether rata men lee Example of son: bape {a ol tna st when mend 20:13 {ng ol tings whan mane 0:1 eve youth apo secon pet ste aven ou the i angth ‘te ironed ony 0 boca ha maxon was 10. (CString function - stremp | eompare he to sings andelums an nfege ae If oth the singe ae sare {emu hasta tncr wud run Osborne nay eum mega a Pots ‘Sto based onthe cpanoon ‘ang < sng? OR sting ea subsving of suing ent wold esa 2 ogni abe tt tiga han uous reise {ang == singa er you woud et ao) when ou ve th anton or ‘ampare sigs ‘example of stem: er) «ena (CString function = strcmp Sntgenrc {Tongans bon fe ing fn aracs cin oh worst comostesisn Garster ofoaane sage. examale of serene: Ste Sn ¢ Senet da bapa (CString function -streat ‘ender os and tus he covets ss. ‘Bap of ect (CString function = strncat ‘Tncainetse choral ofa ob sterner car (10) wl aay [apeensad athe andthe oneness ane ‘example of seat Sit} ass ae. ouput: caapagaeng oo rainy nach ae, 2262) Ee te wnasignedehotand name. (ret: Hangmet rs nent jot cons etn charac ot 2b (Gate: erg ofa cnton Sop a he carat wr a ae ‘Srpené ovr rmination oes ng orf mae ample of serene (CString function = strchr {haves gp cha war taht ata oo ‘rion The ing enon wo ge ary charactor wf sig st fen ial (es comertad to ager beer sarang ur renner, a) ‘i sith ncn sy, te ry itrence stat saree he tigi ‘ras, tow you wnddhine undeanow hy we how asta anche Jouguesed tcc Histor verse ow estate ne se shove ena oupu: ‘iy Sup tree han src? his cae stared searching hm te ent ‘Tow ang and foun be tet incon wlad OF (CString function - strstr Be a eit rang mind oe example of seat: Set EEN ae ae mae ups ‘You can ao due te funcion im place of stchy as you ste slowed o give single or looln pleat soaet orm ae. ‘ines, Cris, * an & opty, Pier ope dean snd ‘Digan une athe Cal'by ence Pang pac ae ‘Beer Ptr nos omer pore Ara re Pointers in C Programming with examples, [Apolnerica atl at tes th ous of onota aal. Une oar {hanes anal aes ef ceran pepe aus he acces fa ale Foraxarol nor vas has or you can cay aor) at re ee ‘awovar en oger parece sar fatter vant. nN 9d, Wo ‘alascins sone Csoganmng mn beep o earaies Setore ne acu att eae el nap unereand ‘th Sawa mean ye erent A simple example to understand how to access the address of ‘variable without pointers? ‘nis program, wo hve 2 vari rum lr pe. Tho ele of nun 10 an 6 ‘ide man se vegsareutareim tne momar rah” Amemory some ames ‘creat vane baths he vue cl that anal he amar space ast ‘stbess For enmgte wave tr afeean norton tas sires we eles ‘Sharpie tne ourhoue Tha some nay hvac evar moved Inemery adores which hops eC pega tot ha va wen Ineo. ‘Sets ny he ashes aeeqresto varie num smn hich means ‘state nde we woud be mng tt sau be ire 5 ‘Beton omnes So he dram bolo bapa: sum sabe name 0 = Vale of um onmse94ac58 ~ ‘dress frum A Simple Example of Pointers in C ‘has at we ean ao wh porter we hae cane tart aes gue Ft ‘Tow wet naed ohn how in apo adios of oa Important pot o note: The ds 7p of pte nthe varie must mah, an ‘neta ane te autor crv ply oly cecued wih al ‘ape ca holst een a Tot varie no crop baow hs Pon ‘mete vara toh ae ta pe. up C Pointers - Operators that are used with Pointers “Address of” (&) Operator We have aed seen inte ee earl hate can clay he ans ‘obo veg amps Thaw od Brum ae to aon fatale ‘nim Tho permor san tnoun se “aderene of person Feros Sas arta cho wee sta tg ne atc ‘Sdreas in sone tne aaa? Tats wreas pobre comes nts pare: At ‘anton n ne begring ate use parton pang ae wat ‘kang ho ose aroer vant ‘Pent ut the ncn he main rece tat ren “Value at Address” (*) Operator ‘Te Optra nea a ta opr yuan soctr we can aces te vaio arable tough a pita Pavanareie Woosoup, {sl cng eve tse The steel hve wl hae act is Say wohave a char vrai hand's pain pr at ote he aes fh Example of Pointer demonstrating the use of & and * Deitsiete rMSths0| Cae apolar tresthe lest wee va ‘hed yp of ple p an ase sod match bec an eeprpober an ely ai eae terval ‘isan oo rate wag MULL YW glu van cae yous ak ‘a naan Sea! Thode tre ote Sosotan A {me ats aged ULL eee 9 mapa "Te MULL per ta cont wh # ae Ste seals Cedar pga anes han sh de sampled an ens prone teow eat (Dui at memay "a veane’ ye few yt renee eae ‘hom Ons sus staan tap hl ne pein oan Spach SSS TR Stee opowtorctng C- Pointer to Pointer (Double Pointer) with example ‘Nica ev apne ni enn mer let ae ne, Wen mer SLES echepracnact opps tee panta Sere egeany fosninaarcanga rset How to declare a Pointer to Pointer (Double Pointer) inc? Leto cnet tie on whe haf grr ~ Double pointer memory presentation Sona Slatin rep Example of double Pointer PAMEINES Semis ie Bhs 2h, Passing pointer to a function in C with example ‘ns ial you wit bam hwo pss opto afrtn 2s an agnor To “nde nd cana you mas hove tone en Sorter nda a propane. tthe any ota pes can lo be assed non a on “igorant Lette scare ocean done Example: Passing Pointer to a Function in C Programming. ‘nis enamel, ate Sasng 3 porte wo afuncton Ven we ass a ont 26 ‘Sh roumort ne of aval thane sderes ha vorino poste aed li So ry ctangemase oy na neon sage parr farmanesy, ‘rete atts snd arb. T iow aby oes “Tye same progam without pore, you woud hat he bons aman wl at ‘oto sly le bosaa ts Ghango nase by to uncon woud done ‘Ee alerts ne con hoo ae ponte a chro Se ae, wy Example 2: Swapping two numbers using Pointers ‘Tai one lhe mot pon earl ha shows tow snap rnb sina cl reece Tre program lout pars, ou woud so tha harbors oa wae ‘Trestons sam halve nave seen above ie it expe, C- Function Pointer with examples ‘1c pgaing langue we canta a cong of Poni neon nn {sfunclon pera nas wes am tow nares {ante and owt cal sina sighs amie Te snr eS Ou ‘rol have ne bas knwo of ures ard Pos NG How to declare a function pointer? Forenarele ” ‘Me tion bet dove yp ad th seco gant Sa pe {Giclee an ftw navies anahrtatu sum Woteve Ses opoar {pint poinato anion we a iokng We nton vn sue pa 2 8h ay, ings a ~“ up: {$Skitiaiea meres Yaren cache incon oe ‘wren nina gi slzoment ihe ie Scere thang to ater use ncn ‘Senbotwrtan etme: ona stow scteren Pointer and Array in C programming with example ‘ne oe wo wis fow wot wih Pes ac aray ns progen. ‘Roamans you lorry ana Parsons fre gna naa ue ‘Rat wo bo os lr yu indo to canon xpameso. Asimple example to print the address of array elements etre yet es ‘Se ofan ger heh mane athe loan eee crsnoane ‘iroqune memory ears nh marae ha dagram ou) GaSe ee ee ey noon ‘nw above example have we alo get te ake lett be {ey econ san tr tn st aia awa om Example - Array and Pointer Example in C ec cage THE, 9, a8 98,68, 77: tng an of a) pee fee teerio sie netfee tn ats “he Oupee ile) aan tet geri SH She be Sees Sea SHEL cis i sic ict b oie SUE: SS sess Soc 2}¥ovn lows say nano ole th peor oe Secddoethearayrame snes euler othe base aes lth aay. tate: "tb te rerearcpesonr) spared on he pie vail {ne nxt can (ox ors xan). hs one sa ro pe of ‘eye forall ype aut, ca oe) eon Rouge Byes Sveum by ‘toh gas pew ret einer ogi ‘Yau mist havo unestoesthe lon above cao so now sme pay wth ow one antes eres ‘Tarai eg we can rs ena tar wy ha Enecnm mama Pintle oS nso 8 sth hr iin omic ins pee opie: Gs mins cn pons heated con ican alacant!

You might also like