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

C Programming

C program lab

Uploaded by

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

C Programming

C program lab

Uploaded by

Manikanta
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 42
C- Languge + Used to communicate Lith then, Language is +. ge ins Huctoy. that means ox are giving 40 do certaih work: computen language with Compaten- Computer is a Softwave ©>) Predefines langtige having Sek of ProgYams + ig Used 40 Comrreetinicgs, Ned ie _Coopiateat language « User For Complex pyro blems Solving TF a Person Communicate with compute we meed 40 Comm unicat coith com putes Understandle lahguage that is binaay language (totter). “The compiley ae P | Con Verks asten bly lan guage into binayy language &Y Machine (arguage: Progryam + Sek of in styactions + compiley iS a predefined program (oi SoFEwaye + : Machines makes OU tacks casih; 5 i a c language is a &tuctared language Intevfate + et rf you wank +o Connect cvith Machines You ‘don't be a 10g Va mm er) + Ex! you wank +o withdyaw money fom ATM: - ‘ tr terface is Yothing bak ah applica hon Rey ver) Progra mimes l, Develops. -- applications Types of applications + web- applications Standalone must be installed uotthouk ‘stalling in oun computer we Can Use them ¢ table for pila ie Independent of Single Operating . fi . System Operating System t ee VLE» m-sofFice, _ Youn cn chrome + Groogla» Com Oral: com Eile ertensions > ) abe . tak —x—+,VLc xyz 4 m pi’ 9 == Amott pad Opererting sustem ~ Extensions Winclows —>» vee Mac. —_r dmg Linux ——> . 1pm, * tan {n 0% Applicerttons clesay epencher| C operallrg syle): Programming language 4 CL plabl foun depriclent cay d L “Tow ble 10% eurlep Standalone gong one ele dle ! 6 ehylon } f Erernclione Opps { Of “rich : trulallation — Oreltold) Plat for indeyrtenl langue , is toorrlaton : a [orf uae car, develop both Standalone carr4 ‘Useb- Oppar Cl ctr osu “nourdlay ¢ Used fox crnbeded 44 ctor Proyiommni ng end C+t ic used for qerroing application, Th c++ hos bigheck library {or qacrning: plat fown ° de pendency in €y Windows > C+ ele mac ce drag 7 eT windows = Crete compilyy +Cibroy a ~ mac =) codmng = compilert library Compiley wor king fon pect (ic Operating system ~ Compiley conver ts Source Cocke ino Machin code+ In which platform We Compit, the language in that Plat for only we “Can Yun Vaviablu. - rremovy locertion syntax rf [|e Cater ty pe Identifier; Ex; links ap “are lop | hn RLY pyinEC a); Named memory location’ ic Called verviccte, “Seti ngs iden ties +0 rnemomy loca Hon by which We Can Process information eFfec tively ‘ Functions © methocls + Sybtaxs Tdenti€y ( arguement = list) 5 b input a prectsting. in put s netuin — ty Pe outpat block oF instuc tions having identity ig Manda toy: add C int x, inEy) tht Z = ¥tys 4 cw Teta 3 5 YI HS ‘doing ‘Sométasks thak ‘mean You ore. feinctioning , Program + Function definition , Function call Remote controle, Functions in € | Is No Avguoments § No. nretom, values Void fun ( votd ) fun): ; a» with arguamen fs € NO return Values. Void fun (ink x) | Ui k 5 fun (10); \ | 3) with arguemebts and retain valas; | ints fun ( chay re) actuary 133 ry ink X=! Luo C9 '); ’ Me No aagutrachl¢ Uoith rnetam valor: float fun ( void ) {.. elayn 2456; 4 Float % = fan( ) Libyawy:- To ence our C applicationg Pre cle fined progiome sec! Heacley fie ts a function of Col lection of ‘predefined functions: i Cc Ubray is a Collec fioh of healer Files. TDE t Tintegrated — le velopment enviowrnts Cy C++ ——> windows Mac Li Nox Blue acreen( IDE | Con sole ( Black} “ Blue ( Editon] ao soe oy Fh 1 AlE +FES compik — Alt +Fq Run — cob + F9 Bako ect Syntax : ata type inlentifiers €xy Ink a3 Repyesen tation of data fs Krewh ag Data type g Classi fication \ “use rcte fined primtive / Devived int Ayay +> 8 buchoy chan pointe» t—+ Union Floak t Noid pe det > enum Signed —r +ve | -ve unsigned — +Vve Shot; 2 bytes. * ink <= wnE 2, 4 bykes on - long U bytes Chain’ 7, Signed SS 4 yy Byte: On signed Cy bytes} Floak Fisk <— double (a bytes] long clouble { to bytes) l Byte = Bbits Unsigned ShorE — 9 bytes al€ =" 65536 = 6 to 65535 Signed Short } —> 9 byte — 65836 z —390768 to 30763 ~ 52768 Signed declanactior) Pe Shork a 5° . & ShovE ink az 7. d format ow Specifiesis Signed ShovE ink a: Unsigned declaration 7 unsigned Short ay oy’ an Lu Ongigned Short int a 5 = ) +4 ‘ f A¥ include include < Conior h> main( ) £ Short A = (0; ely sey C)5 PrINER (CS dO") as 3 Signed Short — 39768 to 397467 ENE ve # include < stdioh > yttinclude < conio: h> c- main C ) fo ; Xu ‘ "Shore X= 2 096q [-39%63] clyseyve) 3 PrirEE CA dX) Uncigqned! clicle ‘ © lo (ve Ob signed sthowlov Vy . Chien jy pyink (OM uy yy | 656 2 ~y Uyjle © 98-956 a Sign wel P1998 “lo Loy chan l= ™ ~ Ob signed ly Ibyte 2. 95¢ > O-lo O55 Stonecl Yange +. y« - / o Je tH WOB lo 1a T] tiby how! Uerit He presenslertion in ‘nleges 3) Hous cary we &lore a Symbol into ( Pyle ‘of racnory 9 63) what ig chanacles Systean HW Whak We |, ASCH, character system Using choractea System We Can Hepirs,,, an endive language. Ex! English: Asc) Chanacten system + Americans Standard Code fo2 inforrnarticn, techhobg y \- -A- 65 a- 44 o- 48 B- 66 b— 98 14 | : ' | A \ ( 1-9 Js 3-199 4-64 35 pee ano!) 1 + include stdiosh> maine) if | Chan ch ="! PYiINEF (Ye "S ch’)j ou; A prinEf (Cs wd % ch): ouks es 1 = tp inclade main( ) chaach = ee SZ printfCs fd" ch) ae PrinEE ("AC ",ch)5 t 4 Un Khoush chanactes Printesr b Waite al iC Program _to _cisplig ASC. valae of chan 9 Hhinclude z stdior h> matin > Chan chy | : PrinEf (* entra one character ;*): Seanf (“fc ,%ch)5 ¢ rai memory location to ch) PYINEFC’ “Asctl value is ted “ych) iy Shing h Stdiowh conioh Stiles yy Pyinkf(); clrscv)s Styraeve )} qetch( yy Jraphics ch get dater 5, | gee irnel 5 | + Colourtd; ) Sizeof( ) ie v Predefined function Pare | TE metuins “the ste of rekirn thing. | oye, DO Navia ble: . . 2) Bata+bype 3) CLpression 7 eesr | | 2) Lirwibs of ei Wy Vimitssh . Ly 1- predefined Variable. trlobal Vaviables | &e Cay @CCCAS i Copp yor Constants ( vor Can't | mneclity | aHtinclade < stdiosly > main ( ) » chav ie pt Shot s 5 4 i print¢ C Sizeof chan! +/. d state) ' oO) nr PrinkEc™ Size of chan y+, ef bylegs) \y", Sizeo€ ( cys “PYINEE(™ Sire of chant fd stxe(s)); Prinke (« Sire of floak ; tod", sire of a (flat) )3 : ere dyes Aor 44 Hinclude< stdioh> x include < conio h> 4k include < limits +h > main C) 3 5 limits +h: Global variable, = —\y le Shot + headevfile inks _ § SHRTL MIN ~~ *) INT — MIN” SHRT_ Max Int = MAY | Lnsis- on OSHRT_ Maye VINT_ MAX Prine ("signed Short min Value corktanlks tong Lone — 1419) LoNG — May ULONG — my i hd \h, SARTRMp, Prink E(* Signed shoat mar abe hed Ly shen y prints wnsigned shomt max valueis/dln, USHRT~M Ax); Modify operato>s s Uniary Operators, Modif * : é & Nn opraaton Can Revfomn operate on Vv Singh speranel: Trerement elecrern’nt (IN¢) C vec) JN LN eine b- Predacre Post Pre— increment Pos! =menk decrement ‘increment [++ No aiakte} (van +4] [- -van} { Vay --} SS ink L =t0} Bee tH [t+ nord ae Seer (x=x+1] x=4 (rs-1] Pre - Increment Bre- decrement Post i Gemmen post decrement Pre - INcremen L | posk- incvemenk > Main () ink xX Elo ry 5 Ye 44X35 . VINER CY dd" yx y Prin EF ( pH) 3 a eu [zt ink Xs 10) y5 Ys W4ts print (nda ved 5 vi s 6 WN t0 main C ) t inE X =t0 , Y= 90,35 ° Ss t+ eK Hy 5? PIMEFC dy Ved) “id's Gy,3) Selution:- he y = (4 —> pne- clectement 9', 10 * 19 +, subs ttation. 2s Bld 2 Evaluation : YW 3 = l40 5 Assigning vqlues. Se Kat sD Past inclement Xs Yo3 dod 4d ul 14 (90 main() { ink Xe ee cs te htt +495 “PYIOEE(S hd", 4) , . v 3 13 Ir 44H = Go +7 preinciernent a x26 ~ Substitution. BR 6 46 =» fvaluation qs lp a Assigning §' B — — Posk increment Conditional statements a if Q: TL- else 3. Nested i€ - else ye else-if ladden. Dre- cise: Syn tox “TE Ceondition ) few 4 else t. chur Statements : Fat foow msg 3 2 provicling optional inforenation to cndusey i condition fails cS la it) write a Program to check “the given Numben is even @xy odd number #Hinclucle < stdioh> im H inclucle < conio:h> ink maint ink a; clysevey PrinE C™ enter a nam ben j or Scanf(“ Q is sp d 52D) iP (avo ==0) d PrinkC* the given number is even"): 2 else § printf ("The given mumben to oclel MUVOby y g “Note: rn the deFinitfon oF i€ = b lock | if we donk Specify ‘using block {4 , only Livek “chatemenk considered ras | | if - block | skatemen Es es Nectede the blocks) 5! iqpt PhD f iO 3" y “pre else 2 else 5 ' #O4 [Bike] | [Stare Ricker Loops t Loops ant used 10 repeatedly execute & block of Cocle as. long a6 Specified Condi-+ton is tree 1s For loop ( mo OF ievations known) i itera tions Unkrs a: while loop Cno Pe ta Hong heen 3. Bo- while loop ( executes atleast st ", Us Break and Continue Skatements For loopy lmben 0" therein: jenoush For > Keg board: i _ Sites © a ®. fov ( tnifialtgotS5 pond Mion von b-Oe Statements ; J As long as Condition is true the _ iterations sepeated » Initial zation for (fst jy t< s105 itt) PrinEEC’ jf i ttadin'y ri ve wiles Hee 4 (Sum of Fivsk » mgm bea Values: includkg stdioth > main ( ) : t inE jt y Sum =03 f pryinEE(® enter valu); sean (S wm ts yd Kn)L for (fat j hcn 3 f4+) Sure = Sum +1 3 | 5 | prvinkEC® the Sum of Fire ‘hd sambens is thd", 1, sun 4 perfect number: Sum of factors of given mnumbey CLtpe TEself is equal to Same num ben: en fe 1 2 3 4 5S 6 x *¥ main () inE wy ty sum=o3 printf (“ent b values"); Scamf (S hd ";ken); for CT=13 fen;ityy tL i€ Gmbh = x0) 2 Sum = Sum +i; y y _. EC nst=sum) t Prine F (" Perfeck number"); 5 else 2 print (* Not benfect nambe a"); 5 Nested while lating wWhill th side anothey while loop Syntax uhile ( outen — Con) t => ottencohile Starfemen ty + while ( tanner con) . =~ in wo} whik Statement ; J > outeawhilt statements ; i kL) While loop i- uohile ( condition ’}) } ue ae +o he executed! y ink t= Oy ' while Cizs) { . printf (9 wdinty i); “Atty 4 09 - while do { [| code +0 be executed Y wahile (condition ) 5 Prion gears a2) ye §e3 ye \<5 j=) ane ny x x ico ¥ YY XY x x te3 XY XY yY ¥ Tey x Y xy“ ¥ fies X ¥F 4 Kx for ( Pot; tees 5 T4++) 2 for (Jet Je =ssstt) t print € (“x "); prinE(’ \h"); $ x x tL NG Kx x x xX x | x OY xX x % for Cf =15 fess +t) for (j =tj3 Jeet 5 J+) i prinEE(* ke ")y prinEFC “\n") 5: %, (oy Mok oO L, Number having & factors. a YS GF, count = 9 prime numbes Progyarn in Ce main( ) { inE Woh, Counk=03 PrinE EC enter Valives 5 Scant (* ted Tk ns for (T=15 igen; ttt) if (my ts =0) t it count ap 3 5 1 TP Ccount==t) f PrinE ("prime number"); 4 else f, : prinE(C: NOE q. prime’); Els Printing Shong numbexs in the given Yang r H indudeg stdioh> main¢) { ink limits r : Nead limik; : H for (wel; (< =Uimit | N44) | Sum =0; while (n yo) t ne ” 1 on ‘fact ai; for Cis nj dpe i3i--) t, foc = fack & ij 5 Sum- =) Sum+ fack; my Nee H/o: if (n= = sam’) no PHIAEBS (NY sting (nin), @SEong Numben:- Ne (U5 / factovials of individual digit in number is dum is cqual--> same numbea. main ( df * inE y y temp, 1, Fack » 4uUm =O Yead 3 temp = v3 tahile (m>0) A= WhO; fact =; ; foy (t= myi r=1;t--) t fact = fackat ; Sum =. sum tfack; a : Ws vet L105. ‘ © ' ! 2 Ba Ga Fibonacci gevtecy an Ab inclad:< gbdiowh> ink main’) { ink my aro, bel,C} prinkf ("end lin ide") Scant ON th di" wn ys for (f= 13 Tam; ian) : { relat palindro ree onan bes program i A Aura kes” ic katd +o palindrome ‘numben | ie hie mevensal of given ‘Number t4 equal -b Same number: Hincluds< stdionh> ink main() { ink myn, 4um0) 5 ‘ = W'h10; Sum = Sunn *16+n5 = /Ilo3 » N= temp; “ie (== sum) J PrinEE(® PalindYomé numba); y : ; else i “ry : Prin EF (4 Nok.a pa lin drome; 5 3 Armsatyeng numben program 4 The Sum of individual digits (calei equals -f0 Same pi muniben # 1.53 m= 134.534 33 = T+ 195 +oF yn = [83 Hinclade< Stdionh > ink main () 4: inE M,C, SUM =O ,TeMmp 5 printE(4 enter hh valoes "Ds seanf (2d 8 emi ctu EC 1 : While ( n ~o) te a= NM) lo5 C= n¥N*N gum = sern+e 5 nn = [los y ~ = teenp ' 2 if (» == sum) prinLEC* Avmshong")! else Prink £(" Nok Armatichg’) ; t Revensal numben of given num ben ; N= 153 L, = 35) #Fincluck o) t N= wy. 10; & = SUM *K lo; Um 1) ie colton 5 a Facto nial of a given naam bear - 51 = 5 XGXS KOKI sthinclucle z ¢tdliorh > inE maint) {1 in—E n , fack =I printf (“ender 1 valor “Dy SeanF Cad “wen )5 for ( TEU 3 tz hy 5 BD) fack = feck 7 “print nas fact); 5 Printing Pacers 2 Jeo S50 Tea Tes Tq. foo Yoy yoy y Fer yy yoy fer yy y i=2 yx ot for.( f= oO; TK = 5} i) t ee for ($515) <= 83 j44) t prinef CMR) 5 PYinEFC"\H'); (ov for Cis y siz so ;i-~) for J = i; joo »a--) t printe( UES) f 2 yes PrnEEE “AnD; 4 Printing Pattern . ie ev jet ica ° oa a _’y is] — aia ¥-¥. te2 ee i —Yy vyy aa Yo oYyy ¥ : : ‘outer bop =. PUrmts for isos THY ZI) OMe for (s= 5 fee 4s iH) {print Ce 8); . ; 3 : ~ for (Ke f j Kési 3k), prinkeé Cee } PrinEE(" VB"); 3 printing patterhs + S

You might also like