You are on page 1of 40
“Program te Tower af Ahi a nfttmeludle tml ToH ( tmnt, chaw, chav , chav) 2 { wat ms Print€ (“enter no-of disest”) ¢ Scan ("74") 20) > erstntt ("Requrized Sequence: ")3 SOHC) a)? } Tmt Tou (int, chaw x, chav y! chav 2) { . Te Cas =t) t print® ("the dise xa es changed from %eto /-0"); 7 TOH (m-1,%,2,Y)3 Print€ (“the dise vd changed the to theo nv m~uy)s . 7 04 (m-1,.%,y,%) = % T@ we want te know only the mo of moves n-! taken, just use 2 trect recursion ant calling @ function tndirectly tu other unelw'n ht preqrass fr even aud odd mumbers.°n 10 mumbers, Hin clude CStelig. h> void edd Os void even () tot m=z W global declarclicn fmt maind) { edd), j void edd ¢) { te (nce to) ‘ printt ( "Ldn, nti) ntt+) even ()y 3 retorn 2 4 void even () { Te (nc=10) print? (“d\n m~1)s nd4s odd () 3 j return 7 STRINGS —_o sequence o€ chasacters ended with ‘\o° nott charactes. stngly chowactes qroup of chowactews Syntax.» datatype stoingnarme[ size] ; &x. chay str [20] 7 Rowmot epect@iew fow sting — 7S | jy theve ts mb meed of |& in seon€ for string because string ts omtesnat porter - So, no need “to specify the address gets); de ushile ustng scan€O) for words with emply spaces bof them, { or eromple, “ RAVI TeTA” ple, ScanPC) stops conning with * reaches the empty space and only scan RAVI | F Dot A char stef J -iG oO. p, *P, 5 ° Saetiali Ze. without grveng rstae, we con tent “2 the string U2ke above. &+ char str[J] +1" Good eday\o} 7 char stefi] = “Goody X, y char stv[s] = "Good » vw Character VointerR ah ¢har ch > i ch-sA" a char * P Z Cl p= Bch ; I] p> 2000 *p= A str [s+ “Good”, oe. ae Ip = Geod p40, ptt Il to read Tmebtviduad , Rte ° Greing Buict-iw Fonctions ay striend) length of the string. , Ext © RANE ees strlen) = 3 Oca Gg Syntox ! strien( var name), (2) strepy coptes from source string to destinadtton string © Syntox : strepy ( dest string , srestring ) strepy (str2, stra) _ op strd = RAVI : y ” ' 2 oe (3) strrev() reverse the String &1 Stree sted = "RAVI", strrev( str!) 3 Strt= (VAR, | CH) streat () — Concetenates two stwing s Syntax + “ streat ( deststring , string 1) x! stet = “RAVI stra = “Tega’ Streat ( ‘stry', str2)';, ” atyt = "eaviTed na” (Di stremp() - | ~ compares two strings Syntax: | | ate sh stremp ( st¥2, stot), ~ returns 0 %@ both are equal, ~ relirng -ve 12 strd ¢ stro - returns tve tf std > oO,” (6) strempt( (a) stem epy ()str ~ topy the only ‘n’ characters . Syntax! ctunepy ( str2, strt, ™) ree” strt = GoodMorning + =o" 2) str2 = GoodM, te) strstr CF - read sub string froma string Syntax + stoste ( string Ms ca) strup® ( string) converling the string into Lppercas< Uo) str lus () ~ converting string into Rowerscas® any ater 6) + converling string to Tntege?, C12: atoll) ~ converting string to float. length of string using Frings | | atimcluds | Thelude < string: h> | mt amain.C) | { ‘char: ste [2073 iF Pmt ferigth s i Peintt (“enter mameNn") 5 getsistr) > : Rengths strlen (stx) ; ‘Pringe Cah" @Rength) 5 reluan 0» 4 uote (ory Without using strings | trindude Sstelio+h> Port emoun C) if ooh 7 i ant , tenz char ctrf20] 5 gels (str); for(i=0; stelt) L='\0%s Can) f ten ++ : f mak oy printf (°%d", fen) 2 return 0, printé ("Lrter mous Nn") ) 1% x Write a C program to Fn * Qo oct 2022 d length of- the stving without string Ubrary. atinclude <¢stdio-h> fnt'amain() f Yot 2, St Pength=0 ; char Sif20): print? (“enter steing\r") 2 gets (St) for(f=0 ; sif@] l= ‘\o'3 t++) ‘ ” Pength ++ 3, | a printé (“%d", Pength)s) setv™n OF Program to find wevarce of string ‘dkPnclude tt include < string-h> int main 0) c char Atr [20]; print? (“ynter string") Sea tee te gets (ste); strrey (str)? print (%5" str) i athout using Program ‘ty vevense the steing 4% ” 4 string Ubravsy. atPaclude < stdfo-h> Al Prelude ¢ string-hS nt main 0 f chax sifiol: Tent %, length » sean€ (“9% s") xd) 2 fength =. strfen(st)y for(foo42 ; or ( to faz0 5%--) f print® (S70 ga ttd) 3 return 4 eerie © Progvam tv copy % string + o another string. aAN8nelude ¢ stdio-h> 4h faclude ¢ ststag:b> Pat main) 7 . chox strifiol, stroftel » print? (“enter string”) 7 gets ( str) 7 strepy ( str2, str) ye printf (Se/s", str2) 7 7 foe] tot ' \ Program to copy string to another stving without using skwings trasy. 6/51) abinduds Sot, main) ; PUsty ® i) me char sz [20], $? [20] pints, gets (4); _ for ( P05 etfig[='N0'3 R44) ghee Eat st[i] = tli]; ' _ 5 © Program “te concatenate 59[0I F\o printf (14S) so) return 0, ° 9, aAwo steungs without using firing Rbvary- tfncludk ¢ stdio-h> ' Sent main () { 17 char str[zol, sted [20], str2 [20] tnt fength, t 2 print? (“tnier fret string"); gets (str) 5 ; printP ("enter second string ")3 gets (strd) 9 i for (tao, steittl= ‘AD? 7) f siva[ tergthitt ] = stil: Vs. ' retoen OF © C program lo compare two strings and check. wlhethes’ they are equal ov not . 4tineluds ¢stdio-b> At inclucte < stringsh > fot maint) i char stri[go] stro[so] : 9 tnt m 3 Printf ("enter frst string") gets (strt) 5 print &( "Enter second string Pe) 5 gets (str2) am 5 stremp(, stra, sted)es i@ (myo) printé("strd i> str"); else ig (m40) printe (* stri ¢ ste2")e else printé (‘sted = tr 2") ¢ ~NRRAYS ‘ Crample programs b olsmeuls * - Program 4p read cud cluploy AAAALY q AN inclucle < stdio-h> tnt main 0 j Not arr [po], ° ; Printf ("Crter array of elemenis\n"}, for [ (*o; Peto s Cr+) Scang Cea" Sari [7]) » j for f Ceo9 2 eto ; eth)" Pri Cd" ere Te1) 3 : Program ‘lo road -£fnd average of ‘n’ elements - AMinclude ¢stdio-h> Tat main) { emt m, arr[201, avg + total ZO j PFO Float avg: : printé (“enter no: of elements") 2 sean€ (%%d",.KN)F . ° for( feo; ten? +t) f geang (“%d", xore(t]) 3° total = totolt are(t)s q avg = totat/n 3 printé (“Average a a ong) y retusn 0, ‘ ae : WHHele G freee te find fargest element in array Wnelude Kstdioks tt main ¢) [ int alto] 2 max pn 2 SanF ("scant ("ad 20) 2 for( 2-9 : { fen staa) sean€ ("sd “ga(t])s } . mox = afo] > MCPs te ekhay t i€ (ali) > max) «max = ali) i printe (« Yea", max): retorno ; ‘ wirtte oC program vto find maximum and minimum of én array) watug funcleo n, Ahinelude éstdionh> . Tat max (fat a[20], ‘at w) gone ; be bat Cy max: fort emax = alo) 5 for (fet tens ttt) { 38 (max cali) max = alt] 5 3 return max 3 + fot min ( int af20], tnt m) { Tot 2, min: emin = ately for (fet zten gt+t) { Ge ( aff} < min) seein eal] } return min t 3 int main { . ° tnt are), hn, & 3 scan? (“ef " kn) 2 ) for (to ,tenzitt) I seant (“Ad Bol )2 : priate (Max 1 fal”, max (alae, ni) 2 priot® ("min : 7d", mio (afr07 nd) + return 0; Tnserting fagerting ot elemert wn dtray ——o es ato} afi) af) ata? alu) afc) = | Palle o 1} 2 Bow,., index — end 3 ctedlment apn ele] at) ah of? alu) oo Gels [Te ° (ee y index, inserting at “tage: io porticular ender Bilton pee £ off} = off-d> ; : alpos-4) = elements » uirite a C program to Engert an element 0 an array). atinclude ¢stdio.h> fat main f : printf ("enter efements of arvay\n")? ant altel, ¢, element yn 5 priat ("-thter number of clements,\n ys gean€ ("~d", #P)3 for (isos ten, ta) oo Saanf (“Ad", salt). ? print? (“enter element to fnsert.in an array Nn‘); scant ("%d", telement) 2 + Olt) = clemert 3 Print® (* Kew orray s\n") 7 for ( fey ples tay), * printf ("/.8" off); return oO; > ° write a C PSOgzam to insert on elemert at porticulay position. Aeneluds ¢stdio-h> int main f tnt ale), ia phi, Lemert 5 Sean€ ("4.4" tn); oo print? ("€ntes elements tu array "‘)2 for(i=0; lens tt) f ‘ sean ( "Hd", Bali) 3 cg : printf (“dritu, element To be insestid aul positaan tolune Y bare isrertid *)s Sean ("YdeLd " belement, Spo) + for(bemts fs poatn ste) f ali+id-+ alt; al pos -1J = elemnnl ; *~ priutP ( "lr maw oanoyt"); for (izoz Ten sitt) : printf (thd’ aff); return 0; © write 0 C program to deletion element th an array. logic tor. ( Te posel 3 famargtendss Loe : : 44 atid ote U7 7 . Bor (izozten-15t44) ON “rth ac Pregram using intieh-caie pede operationg Whe Creation , tnrertion » deletion aud dix ploy af on array. HH Tncludee stetio-h s an tut main O c Hl Sant afaol, m, 2 c, eweet » Pos a ertnt¢ Ctntes mo-of efements\n") 3 Seang C= %el" RM) > PrP C" enter egevalion\n") 3 PEALE (“te Creat fon\h &. Prseslian\n 3. Beton sn 4 Display \n")s SEGRE C97. at "g0)- EL r Swttch(¢) f case 1: printf (“enter elements o& asray\n )2 fou (feo stems tea) Scan€ (“oy 4" saltl); break * case Q : primté (" enter efements of avvay\n"), fos (f=0; Pen ptt) Sean€ (Yond" zal); primte (“etes efement and position whese Tt has to be insested\n"); scan€ (%de/a", kelement , 80s) 5 ; mts fow( Pent z t>=pos;t--) a(tj= off; alpos-') = element 7 printf (" New ava is\n") 2 een st4t) gov (P=0% prtoté (Ad Nt", atti); break + case 3 2 printé ("Entes elements ‘in array\n"') for (f=0 ; fen gttt) scant (*7-a", Bo CiT) 3 pointe ("Lnter position where to be deleted "Vs seanf ("%d", #pos)7 fow( t= pos-l ztcn-1zitt) atig = alt+tl; paint? ("New arvay u \t"): fos (f=0; Gen-ls t+) print ("%d", galid) > boeak ; case 4 printé (" enter elements in awway\n") ; fo (feorten str) scant ("e/-d", KOCED) 5 fos (f=0; ten; ttt) print? (%dre’, aff3); boeak » default + printf U Not valrel")y vetosn Oo; Soetiwg 6 6s ing or descend: Arranging elements in etther ascending | order . a Busse Sort —_o ro loge ¢ for(teoy teat site) { tov fos jen-tzd) f 7 . te (atj3> otf+t) : eo" oe aly: © ofjy's of fed; offer ts" (or) ° for (feo; Teng i++) { fow(j=0; jens jtt) { 0 +=afth} f€ (alz] >afjl) | : { t= off; ofti= aljle : aH et: 0 a et Profan : AHinduds< stdio-h > tnt main O ft int af20),,2, 9,4; priot€ (“Enter no-af element") + sean€ ( “%d" B)s, - 1 | for (t=0; Lenz itt) | sean€ (“7d" galtt); for ( f=0; Ten-t3 t+) i forlj=o; gen-enls jt) f #2 ( offJ> alyri)) rt te aljl; aljy= alj+il: affer= ¢ 3 for(teo; fen fH) print (87.4% aliJ); return Dg Senrcnine CY Whear search (Sequential search ) Cr Benary search, Hinear Search ~ Aorted tor) uusorled Lit # [a3 [ac . ae 6 | ieee Prograus — 2 tinclude < stdeo +h > ft main) [ . gat alo], ° 7, ka found = 07 priate (“Enter mo-ofvelem ents ")7 ' Sean€ ("Ad ,); | “for (P20, Fon? t+) scant (“yd" BoliI)2 printf (“enter key”)? sean (“%d" Rkey) y forl iso; Zengt+t) f %@ (Key = -alt)) t print? (“element found at 4A); found =! : breaks }o t€ ( tound ) a print€ (“element ie not found) z 5 “Binary Senrer —— Touly takig sorted Ut tabi le ( tao = Ugh } wuid = (Bow + high )/2.3 TEC kay a (utd) {tow Rayo - uid +1 rece ce erer =Twio-Dimentcionnr —figrély ——- » Syictax : clatatype arrname [rows JL columns] 5 —Ceourpls program : dtinclude < stdeo.h > fat main () 4 fot of 2921, C5 5 print (enter elem el in anitrie AN7 for( f=0; 02 7.044) f for fa0 ; fe2 yt) if : . seonb( ty d", RaliTlfl)2 J J print h-( © tle» eratetr 4 elect au \n") - for(irozic<2; itt) f forlj=0; 4523 jr) print ("y.d\e Valerlp? )e } printt ("\n"); return 0; talite a © prograu to faid —roupete fw one Atindude < stdio-h > tht main() int fog ia], °,j mtrowl2I(215 print ("itr elements tue meabere")s for (fo; i¢2 i449) ‘ for jz0 jer sj tt) seont ("74° goliilg]):- J for (feo, i¢9- eee) fr for (j=0; jea,j++) : f Atrosal tt] = al éIlj17 : 3 for (i=0; te 2-44) f for (Joo; Jc 2; 5H) printf ("7d <0", trawl? JLj7): printf (* An’): i relion 0; wrike a C prof to fried addition af two austhites |) the Aide cI oualuix “uu mxn. APincbucte< stato hs * int main 0 t Sat aftolfto}, b[20IT10), ¢, J. fom [10Jl10) 5 pant (“Giles aire of Ao aud Cobuunt”) ; Seauf (ed 74", gu 2); tor (7200 3 telmy Ore) f for (9207567 yt) scouf “7d! soltIljI) », i printf (tute woibr 8°) ; for Lizoz tem t+) for tja0ppcnagryy S Soup (/al, BOEIQI) 5 -for(t=0, ecm ive) ' oo forljeop fen fet) sump tilj) = olidj+ BLOT] 2 protf(otuas gf Aad OR tortie; tem; i+) f . for foo, jen 3d) pont (1/4 peo liG1); prot ('\n") 5 7 : “retin 2 a ye ° wivite a C program to rmultiply two qiatricos. stinclude tnt matn 0) f Smt alto [to], blioittel, res [toto], © 95K, Fr Sis Pa,G) printé ("enter order of matwix A"); / Seank (“ded %a) .Rer)s printé (“rites oxdes of matzix B"): sean’ (“e/ede/-d", XBy ,2Co)s ie Cole %) print? (“multiplicalion not possible”) 5 else . print® Centex elements in motaix A") 5 for (T20; (68, 33 7 ' : for feo 34013 dt) sean ("%ed", gattIljl); } prot? ("Enter elements tn matrix & a. fo ( f= 0 7 (4 Bt t+t) f fon 205 1400 3544) scant ("%/A", gHrIcp3)s } for (T-0; ica, itt) f efzi{j) = o7 for (J-o:d \ ptr - realloc (ptr, newsize)/ Crowiplt : ptr= sealtoc( 5, uy; { | u) Freel) ‘ ) ~ used to Fret emamory ~ Syntox + gp Reee(Qtrd Wath eal? 7 ‘i en we: are using above unélions; we should use : head's ile st tnt std eieeho Program : Aum of to-terms At frelucde ostdio h> at includle ¢ stdlib- h> nt main () f tat 2 xptr, m, sum =0 5 sean ("+/.a” an)y ptr= (tnt x) ealloc(n, sizeok (inb)) 3 tec ptr = = Nott) oa . print€ ("Memory is fate") exit (0) ¢ ' J Ror (i=0; Peah pied) { ptr +t) ary Sum +> (ptr+i) 3 print eC 4a", som) ; free(ptr); |/ 0 deattocalt memory return Oy oo _— = Seen Commano Line Negumenis ——° t environment) d developme™ aapree Sn 1) uawg TOE ( Zntegrate D cexegile. ( doublk elvek } (1a bit ° chorocter user enter face) 5) Coumand Prompt’ ( mpt by . possing arguments at command BY using maw fundlwoo. i ommand promt - use’ 2 main () - when you wiant to vue have to pass parameters en porameters ens —arg¢ % argument count > felts count of arguments “pagsediins emd prompt « - arg v0} Aik argument vector. § of cmd.\Sauplk-¢ lo 20 loa 2 program leas [1 3 ie [x3 9 20° arge > 3 A main ( tut arge , char eargull) \ by default, argvl) # charactis dataty Pe = Ht taker integos bu 3 ‘ \ : strings ete’ convert stray tb * integer, we funcleon atoi tat main’ (int arge, char f tat ¥, eZ printt CArgumen! count & 7d; argc) 3 for (f20 5 7 < arge + ied) tor 1 7S", argv ti); print # (* Argue ent veel return 0, tut main ( ist orge, char *argut 9) ipl oe court 4 pa" 0r9e); ar alot ( arg ta); b- alo’ (ar v2); Cratb: | printt( “hd '-e)j » beberno % 7 Ds Command prompt + cmd: add-e to 20 3 30

You might also like