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

Programmirg Concepts - Using C: La6 Fulanuaf

The document lists 10 programming problems in C including writing programs to find factors of a number using functions, checking if a string is a palindrome, solving quadratic equations using switch statements, adding and subtracting matrices, and several other programming challenges. It provides the necessary algorithms and code snippets to solve each problem.

Uploaded by

nishi_renu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Programmirg Concepts - Using C: La6 Fulanuaf

The document lists 10 programming problems in C including writing programs to find factors of a number using functions, checking if a string is a palindrome, solving quadratic equations using switch statements, adding and subtracting matrices, and several other programming challenges. It provides the necessary algorithms and code snippets to solve each problem.

Uploaded by

nishi_renu
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

i$l*cafrwr tox Eftailf,st rmrd

FES

Depaltment of BCA PESIT CamFUS,Bengaluru-85

La6 fulanuaf

Programmirg Concepts- Using C


Lab Code: BCA205

frndfE @t5 of qq.d6dc equationusingsritch @. geneEte pnntN Fiboacr numbeG and fnd Gco and Lcil of t'o iniageE [email protected] Int oer and che<t( whetherit is Palindrome or numb.6Pnre o. not5, Writec p@g6mto findwhethe. oivn be no6b.B.nd nndMern, variane,& St .da.d 6, Write P@qEm anput C to 7, w.ite c prc06m to readtwo matrrG a.d prtormaddition& subtracbon 2 of it ornot. a. write c prcgr5mto rdd. strlno.ndch.ckwhether is palindrome uslnq tunction. 9. WriteC prografr to ffndf.cto.lalola numbr

or L writec prcqEmto fnd if..rr.racter ls alph.btic Numeric special or 2 , writec poo6m to @mpute sumof oddandvennlmbe6 lsing fu.ctjon, the 3 . write c prcgam to fnd [email protected] noml of squ.E rEtrix ,sa.g tu.ctions wnte c prcqEmto.c@pta *nte.@and convert.lllowerc* to upper 6e
5 , wnte c pog6m to a@pt difEHt goodswith numhr,Fi@ and date of

pur.na*.nd display tno. 6. whte c pogEm to 6nd tne lsgth of . stnno with@t u5inqbuilt in tunction. wrfte c pdo6m to @pytn @nte.ts ol o.e file into anober WrjteC pogdm to di5play rc6e or a string uEno pointe6. tne

wate a c p-q-m to ind the rcotsof quadEticequatlonusingswltch

*lndude <stdio.h> *lndude <@nlo.h>


{ fl@t a, b, c! d, x, x1, x2, rpadr ipa.tj

pnntfCEntr n(mbe6'), 3 s@nfcq4f%f %e, &n,%b, &c);

x= -ot.i prlntf ('only mt x=%7 31, x); exit0;

if(d>0)

1
pnntl ('Realand disllmt @ts ac "), x 1= C b + s qd(d)/) ( 2 * a ) ; x 2 = ( - b ' s q d ( d ) ) / ( 2 * a ) ; pnntf x l . 7.3f \n x 2 = % 7 1 ' , t r , x ? : . 3 c rcots are )i Prlntf eRepeated x 1= _b/(2* a); 12 = x 1 ; prlntf("x1& x2=%7.3f "I1,x2) i d = sqrt(abs(d))i tpaft = dl (2*6)i rpart = b/ (2*6); rootsae :'); Pdntfe@mplq pdntf cx1 = %7.3f + I % 7.3fl, rpart, toart )i pd.tfCx2 = %7.3f r % 7.3e,tPaGlpaft);
)

gtch0; Eturn;

i/

wnte a c prosbm to ftd Algarfthm: 1, 2, 3, 4, 5. 6. 7. a.

a stnng and cl'ek whether lt ls a palindEm or not

I.PUI a strlng Count the number of daEcte6 In a stttng lslng strlen function Dlvlde skin9 by two the lncement the first part by 1 and d*rement the next part fBm l.st by 1 Match chaE on eithersldetlll th cnter the If th chadcteB on elther sid match then th *nng b a pallndrcme lfnot, is not a palhdrcm Stop

*lnclnde<stdio.h> *lnclude<@nio,h> void maino char.trll0l; Int l,length; PrlntfCEntrthe strlns); Length=stnen{str); Fo(l-o; l<length/2;i++ )
{

r (.vll r= srrflength-1-il)
PnntfC%s ls nota palindFme',str),

Exito;
,

ndFme',str), Printf("%s a paft ls


)

Entertne $rrng: madam

Bdk is not a Pallndbme

theglven .umberis Pnheor not.

nunber lsa nuBbr A Prtme dlvlsrble by ltslf and by 1

prlntrCEntera number")j $nf c%d", &.);


{

Ifthe n <= l displ6y nota ld Prlnt l. not a Prhe number El* ls a Pdmenumbr

prrntf c%d ls not a pnhe no", n);

stcho; exrto;

' '

for(i=2;r<= r/2; r++)


{

lr(n%l = = 0)
{

pdntfC%drs.ot pnme ");


) )

pdntf('%d rsprlme n); ",


)

Wrlt a C Fqtm to Inputa sdt6 ot dmber ard nnd th.Nrnen, v.,i.r, .ltni| rd d4tat on

*ldude <stdlo.h> *hdude <dlo.h>


{

int |, n; fl@t sd. 3!n=0Fuhsqr.0, mon. vatue,v.d.nc!=o, .l1ool; clM()j printt cEn.b no of d.r. potnr.r); $nf C96d",&n); prhtr Cqt . d.ta potnE')i n)r (-O; l<n' l++)
{

prtnrCpohBq6d',Fr)j sif c%r, a.fll; 3um=sn+.[];


r *m/n;

s.Eqr . o, tor0.o; t<n;t++) { valw = a01- non, t sudsqr=sumsqr vatues vrtu.i +


vartano ! ensq. /n; sd = sq.t(ed.@); prrrtf c||rs ! r|5r, n4n); prinrf cad = %r, sd); 9etch0' Fn m;
) )

|En

Ente. dE moa&t

polnE:4

5 d : 4,5 3 2 1 1

w.lte. c proqEn to Ed tro m.td6.nd

Derfom addltonandsubt6ctlonof

Matrrx. an a@y ot numbFamnc.d h @ and@lunns l6hlo rs of 2, Re.d the elements matrlxA .nd .heck for the numbrot 6ws and of for of 3. R$d the elements matn! B.nd check the number bws and erEr 4. If numberof ws and.dumG doesnot natch then dlsplay 5. 6. 7. 3. If mrtches, then perfom .ddldon .nd subtEction Add natriia&a (slil = A[] + a[] ) subt6.t nafix a & B (olil = A[ll - a[] ) OBpl.y the $n slil and dliene D0l of t*o matriG.

bl 101 Inr.[10]t101, r0l [10 ] , s [ 1 0 ] t 1 0 l, d [ 1 0 ] 1i, l, n ;, pnmf center th orderot matdx"); snr ('e.d', ar); printf cEnte. tne elements rutrlx a "); of for (l=oj i<n; i++ ) ror(,=0;j<n;l++ ) s@nt C%d', &!liltjl); prr.tf ('Enter lements matrlx "); B the of lor {l=0; l<n; i++ ) ror(J =0i <n'l ++ ) J s@nf("%di &bttlul); for(l =0;l <n; l ++ ) ror (l=0; l<'; i++ )
{

sumtiltjl = alrl0l + blllul; difftiltll = aliltjl + bllul'

pnntfcslmof matrix "); ror(=0; r<n;i++ )


{

ror(i=oj l<n; l++ )

t
) )

oinrf c%4d" slmtrlljl )

("Difiren@ natrlx"); or Prlntf 60r(l=0; l<n; i++ )

{ ) ,

prlnd C%4d', d rll1[ll

Enterthe od.r ot M.t ir: 3 Enterthe elem.ntsor [atdx A t23456749 Ente.the demsts of natrlx B 234567690

( 3 s 71 9 11 13 1

1 15

1?

'i

I -1

L- r - 1 eJ

f -' '' -i) -1 -rl

wnte a c prcsEn to find ftorral a numberchq tundlon of

2. 3, 4, 5.

lnputa numDern = lnltlallzethe @unter 1r tact= 1 dlglts using filn 1to n Forloop counttie numberof fact Compute = fdct* I untili-n

*tndude<stdto.h> *rndude<@nlo.h>
{

(ht lons ractori6r n); pnntf(iEnter Inteqer'); an s@nrC%d'lan)i prlntfCFa.torial %d = %ld",n.fdctorl.(n), of


,

n) lonsfactonal(lnt
{

for (i=1; l<=n; l++ )


)

Iab Prcgrams
to wnt a CSrogEm leredte ihe 1" tl

Oddno: Ga whendivld.d bY2 rctuhs Ecn no: is a whendlvlddbv2 returB

I
prinn {"Enterhd manv ths ? ");

2. Dividnby2(FnZ) 3. lf F0 thnnoken 4. lf Fl then no k odd

ant write a c prc8Emto rqe an Inteer palindrome not or chdk wierher th nols
{

5. c.lculat@@'10+rcm 6. C.nnnuedlGel.ulation ontlith wholenoh rveue! 7. P.intthe t4r*d number 15 3. lt the r*n th. pnnt$'e numbr p6lind6ne el* not a palindEme

t pnnt("961d Faliidbme", C); o isa


pdntfl"Xld it id a P.lhdbme", o.D;

wfie r c pradn ro GcD& LcMof 2 numb.B.

L |.p'n2ht gF.,!

a r|uhrly.& b.d.sln hto.


t nponryknabk lt hF..b)

pn f('Ent r2|mqEa,brI s'f ('!6rl*d', &., 96&blj

l pd'||fl'kn .ta4 acd.td, bn,!cd);

Write a C pFgEn to nnd |f a ch.r rs .lptabedc, nuDbr or sp.dat .tEE.rer.

lnplt a daFcter Comp.re the char.der wrth 'a!'z' and 'A4z' If matches, chaEcter15 then the qrven Alphabettc Conpare the ch.r.cter wlth 0 9 If matds, thn th. llwn chadct .ls l'lufienc Elslt is. sD.d.l.na6d6

pnr f cEnter..h.r..rer'); rl{(.h>=a' &ecn<-t ) (.h>='ri &e.n<= z')) pdntr lsan.lphabet"); CIt

printcrt rsa sFd.l .h.ater);


,

,\ -/

Wrlt . C p|.Cr.m to drA|te ih. *m dod.l.t|d avtn rumbss

6rd &ntun (rnt.l l, Int n);


(

1. hplt r 4d6 of nunb.6 2. R4d t E numb.6..d lnltLllr. @nt rto I 3. Olvlda Gi nuDb.r by 2 4. If th. rrhrlnder = 0 then .$En tn to 4n se.l.s 5. Il th. Em.lnde l- o oEn 4d9. in t tD odd.dl6 6. C.bLt tlE $m oaodtl .nd aq sl6 et ..By

Int.[15].r,n); o,rn|' chd n.ny numb.6r); sc.nrCc6d',ln):


pthtf CEnter th. [email protected]
');

ol th. llC

lor(l-0; l<n;l++ ) $nr C96d',t !D;

sLt emtun ol*.t l, ft n)


{

|nt l,6un-0,6um=o; io r 0 = 0 ; l< = n , l+ + ) r lr ! 1 9 6 2 = = 0 !m = 6un +.01; dm 6un +.fll; prhtr CSumor en nunbE l. prl.d('l{om o{ oddnumb.r! 15:

Enlarcldrent ln 6. llst L2345 sum of odd nunb.E 13 9 Sun ofeq Nmb.E t.6

Wnte. C Pooim to n.d tFe I nom of t sq6d mttb( u.r4 tundorE

Yord Int ..nun (.t .t101[1o1, n);


hp{t th. dih. ...1 ehrents of . hltl.ll4 ti. slm and Fde = 0 [email protected] th. trace of w6y elemat In . rottlt udnq b.e =
{

rJ,n); rnt{101[1ol, Finu centerttE o(br oa enf c96d', &u; Flnd CEnt. tn. ebrcnts ol rutir
b. (l-O; l<n; l++ )

rEo + !tU01; c.ldl.t moc.gtt

ealue of

Sun lt olqrata uing $m = en

+.trlUl..trtul;

Crlclrt ffi.lqn($m); Dl+lrt th. vdE of tne

and
)

(J'o; i<n; i++ ) 5nr 'or Crsd-,e!I0tjl); Int vold..rtun a[1o][to]. n) ont
{

I n tl, l, t 6 @ = 0 , s m ; lbr (rr0; l<=n; lr+) tl!.! - tEe +.Irl0l; td(l-0; r<=n;r++) t t 0 - o ; l< = n ; l+ + ) sh - $n +.Irtt 1. .!t0li = sqn ($m); 'gn rl|e pdr6 of dtrb. bi i6d', Crb.m or m.tn b: !46.2d-, 'lnl'
)

Ent.r tn. od.r of mtrltr 3 Ent r th. .l.m.nts of m.trlx:

rr 23'\
1455 |

l70e I

i/ 6e.nd

wnte a c cft4m vle EB

to ...att

. aantce

nd @rct

all !,lE

t bsr

. . . .

I.put ! rtrlig i.d dE Lisdr or . inne tdit .lthn tu.do.r r'-'1ltrlll!.ffil!.lb!tF| lf ttE 3th9 nrdE tf ttu 3d4 mdE'rf - 2'n i,l b. dcr.d

otsrby d* 3tnr

to lGE.

*l Elude <stdlo.h> rlnclude <@nro.h> i

prrnu . cEnter s|'lno1;


td (-O; l<hn; l++)
{

lr (st4ll >- .'ai.t (ll <! '/) s{11=3r{ll-32; lr (!t(U >- 'rf ll st'llt <. 'z)

.rt(u.*{[+32;
) )

9.tiat cco.Etad srn4 E *d, .t );

coNri.d

strrnl E hEro

Wrltea pog6m to .@pt dlfieEnt goodswlth nlBbr, pne,6nd puEh.* a.d dlsplaythem dateof

<onept foreasye.d.bllltyand slmple Tils pbgram us* structure

. . . .

date and price Aceptthe detallsofthesoodsllke.ode, nane, purchase Iniuallze. colnter to @!nt numberof goodsmorethanone tf the numberof goodsls lessthan the ounter valueac@ptthe detallsof Drsplay detallsIn . neatfom6t the

t
It charn6mel20l; st u.t date paydat;
,:

"); Printf("HowmanY rtems?

puth.sedate, prlce"); PnntffEnter ltemno,name, s6nf ("%d",&rten1.no); s6nr C%s",&ltenl.name)i p.yd.te dd, &ltem1 Albml.p6ydate, Sanf C%d%d%d', j &ltem!.payd*e.Yy) &lteml.paydate,mm, sdnf C%s",altenl,r.te); Printf("ITEMDETAITS \N'); Pdntt "%d",lteml,no), c\n rtem.ode ('v rrm name Pdnrf '%5", ltenl.n6me); dd, date"%d%d%d', &itehl payd.te Prrnff purchdse 0\n yy); &ltenl,payd.te &ltem1.p6ydate,mm, Pnndc\.ltem prrce '%d", lteml,Fte)i l

To fnd the lenqih of a stnng dthout lstng bullt-h functlon

'. r , . . '

lnput a strlng tntdall4 a @unterI, and lengthI Readth string using ushs getso Rd char by char by hcEmenilng th counterl=l+1 contlaue dll tlte end of sking Countthe numberofch66deB the DlsPlaY @unt.

char name[20]; Int l=0,length; pd.tf (iEnet. a string :");

whlle(namelll != \0') prrnrfcNumberof daracteE in the stnog b q6d",length);


,

Nlmber of chadcteB In the stri.g ls 9

a/

Wrtt r C progEh to ontdts

of d.

Fll. 13 colledon ol co.d5 ! To.opy the e!@ lll.l.to U dcdDtlon llle, both [email protected] dGdmdon fi16 m6t b. dEdng. If ddMdo. 6le d noa.x!a d.t

FILE.hrD, routft; .rEr h.m.[ls], ch; inb=lbr.ncd:\\sampl.C,'i), if (hlp- ULI) { pnnfcEm. h ot.ntno l

2. Select sou@ flte the 3. Opq the we nl.. a, I' nb sisB, op.n In ,ilte nEd. .b. dbd.y .n tu O!.. tlE <t .t|mdon nL dlspl.y a.emrmG*ge

r nlesr5ts, op.. tn. n|et*

bFnCo:\\r.hplc.bar,'!'); ir(o{dp.. r'lutl) 0rind1"$mple.baron.ot b.


) {

a. copY t p

@nt nt. o, s!@

iL

9. nh 13 rc...3tult

@9red

whrl.(.hr=EoF)
{

fplbqch, dtb),
pd.U C$npL.c

.rr.r9.tc(inD);
l. ia6ftilly

Enter tlr. oG

f b Dm:

Ent r th. dGtrnatron lll.i Fll. dG not qist Ent6 dr ddtidod nb:

$mph.c @d.d sl<!tult

To find the Bee

of ! 3ti.9 s5h9 Fhtc6

. . . . . .

Inplt. strlne fterc mnort loodon lbr ttE stnng clng F nteE tr.ad the st r.9 lilm tne b.grn.rno 6rno !ts0 to trnd tn |6stn Red the s|'hg fron b..rw'd5 tty &qll@ttng rh mmry l@t on by t PoCtbn c.ndnu. lndl th. .nd ol 3trl4 ls r6dpd filn eit rr slde. obpl6y the lenoth.nd the .4@ of t E sning

Polnt ri 15tne add|6 of . v.lua In th. m.m.y ltlon,

vord marno
{

charcharstrt2ol,Ev[20]; char *sr, *ru, rd.rt; prr.tr cEnter a sElig : ")'

st++; st --;
{

r t|DE pt. to 6d of tn. 3trh9 ./ ,/. m@ pt b..tby r tG|don./

pnntf COnglEl strlng ls %3', str)t pnntf cRd.6ed strins ls %5i ra)j
]

orlglnal strrngrs R4eed stthg 15

t . ..t

Shuctued Programmi!g
M.le ltc Foalu's loaic<t to li.lalrdl by GiDs! sudl6 scq'E (srEish lid) $'lhE codiriGl (Bmhir8 ) srEre Rcrdit'@ (ldDoi) SaudE ll it t sll d.sig..d pdgl!|Mi.g rehnhE ro dd. sir., .Lbus (clEt 'a.d
Ds!r86 Eddiridl hE hirS [r. CtoTO,BRFAK !!d CONTINTE . . Clq & att !o 'bd.BLtrd

ModularProgramming
ItatSt d for v-y loogud cor@la Flst-s firc $ftE! dct kd.fl D.fd a brElio8 . Lr8. F!e@ iDto odl ird.?a.krt M.dul6 qlcd Pbgm Modul6 e oaui&d i. roFdou Erd EoduL Frforu r ryd. lll .!d fiulb, i3 Grcd *ith tb. Eir B@h Rrli ior Modrl+ . E .h tudul. dbold Fif(m u . . . Comsiqti@ b.r*q modulGt b 6y cdlilg ! hodul.. No co!|ruiotid @ r.r. pb& b.rc. ue.llcd nFdrle Atl bodul.' e <LsisD.d bw lo Sildcdcy ,!d Sincl. dit oaly

Fay 10upddc & bodiS th. Fogtu silho'd bodirying lhc

Arary
CollErio of Eld.d dd ofne B.hlvd liL bult-i! (||r! tyD. d.L tyF

Slruct|tl!
Cotlcri@ of dncd dd. of w dtu ttD. [email protected] fn ddrllwrE Ur.d io dcsign d.chF r rlructuEd oi

s.tchrd)
. . Thk nDcdonk Ed io @d sielc ctoFlar frlb lhe btut !d sta .

S.rctto
h u.d to Mcpt th d.t! sd

.Ih i nrc b-E l rry . . T!. Gdi'S is taltidd .

'\r' d nuuchsrcr ir d!r.d 8 lhc

Sydloric Corutsnrs
Ce arpd eyrd* in in pregm blt befoEit is rcl.ftd in the?mere (n@,lly is de6ned h witt n in pilll lite6 It c@benoitfied fu al@Y Eg PI \alue @ benodified ,i.n ro 3.142 3.141 No Blaik spre bettr@ * ad # nust betle fiFr cheter. Th@ is a bl",k spee betwa @nslalt #dfift ed rhesymbolio TnesFbolic rme ihodd tur be Nirsled oy othrvalE within Eg:#deinePl 3-14159 {q:bfneSTRENGTE 100

Ml'gu/PEItr('..39rDtEti

Prepd6e. is a ptugm lhat pc6es ine sure codb.fc it psss t!rcueb l[e conpilqArc pl@ d in the$re ptug@ soue .od is ermioed for pEpl@sr di6tivs betue @npiling. IftheF @ dY, lppbpriai. a.tios e takd sd llo theprcgd is st ro Tneirerd&r is: dey bginin @lum oneod i3 not imimld Es:#irclude(spdifi.s ff16 to beincluded) (defc na@ sbnitutior) #de6nc *udf (uilefG a '@m)

. .

Is e .qu4lity or rclatiotal oP@tor D6 nol cbdep rhe valE ofth Eiable or the left bdd sidoI lhe Nigm@t st tenar

op@tor ihat Is d sigl|Mt 6sigG lhe 6uli.nr \he on rhe right h@d sideb rhe vdiable on Ch6g6 the val@ oftn YdiabL on tn bft hed sideofthe 6sig!En1 statmmt Port' iocrcrmt dffidot

-.

PE ilcrcbdt

d.dn@t

r- imov

amot

decm6ts rhe 6rst in@dtv val@by I dd [h ssierBlhe valre ro lhe vEiable oDthe bn

oeoo. I

Postietadt/ deM@l oPr.ff 6Ft sieN theElue ro 0F vdiabl onrhebn n nd side&d $d immaiJ d@dis tne

Eg int p,q;
The vd@ of D is fisl in@er d bY I trd thn val@ is ;siFed ro q, !lE ofq is 6

Theval@ofp is 6sl Nigned to q &d tha ir is de@noted bY1,but val@of P is 2.

You might also like