0% found this document useful (0 votes)
5 views17 pages

C programming

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

C programming

Problems
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Totreductan te jammin

Assianment

A400]A0552
Wite (-Proyam how
to nd many timg each Key
element i Preyent in an artay.

t incu de<stdio:h>
+in du deeCotio .h>
veid man ()

int

clrscrc);

Print(Enter n value i
Acan? (.Q ".
a)

{forli=l;icen;i++)
Beant(%d
"axca):
Pvintf

for
("arr
ay

(i=l;i=nsit)
elements are ; t
{

}
Prtt Enter a Ky: )

(n
Print
t++;
key element found at td,i);
it (t)
Printf (^key plement mot feund):

Pintt( n ky element found d times. t);

(ttitnasiglei)ye

Outrut:

Enter

4 elementa 1 13

array elements ue s 1 1 3

tnter a ky:1 ./ihxh)f)


key clement found at o
key tlment Pound at

key element found 2 time.an s>i)


a) wite a c-Progran to eliminating dpliate element in

an

#ineude<stdio.h>
void main ()
int
apo]:,i,kn;
Print? (Enter st3e3 "):

Pint \ Entur d elmenta


n );
for (izo;
ten;it1)

for
(io;fenzít+)

(at3- a1)

n--)
j--5

hint(nAtu elininatfny
dupliaty
toor (t-osfeng i++)

Pyint("td", a(1);
(0cio icv
}

OutRit:

Enter ize :5
Enter 5 elements % 51
Ater elininadig dupliatea i :5113
3) ite c-Proram to fnd noof bords, ns, chaaetory
a c-Projam
in ven tring.

#inculeetdo.h
#mcudeestte
void main ()
h>NeAeeonw)in
Long cha, lword,ine;
int c,lag

charo;
Line = Word o;
Print Fnter the

chatt}

lne tt

else
}
n No.of Words d", word)
intt ("No.of lines d", ne),
Aint (\n No.of characters 4",cha)

Otput%

9
Enter the hing row
1: JNTVA College
Anantapur

9
Noof charattey-
21ll

()
)wite (-Projram to Bort aray o tringa by yang

ting handliny funtton s


#dude< sttoh
+ incudee sing h >
void
main)

char
int ij:
stings
[s][aoo], tempro) ;
for(t-eg ie5;it);
{

for ( t=0; iej; it+)

fr(ieijss;jt)

{
stror(temf,stinyca);

stite
(4htny().temp)1
tor (?so;
iz5;i++)

}
Outpits

Enter 5
zebya
dot
Cat

elephant
ant

Borted tviry a;
ant
Cat

do
elephant (ttiictist)
zebya
5) write a C-Proaramn to read 2 terent strtnsg and
c-

Pfnd haww many tfmed tying 2 fs appreared in ting1.


+indudde < stdio.h>
+ incudee
sting-h>
int occur (longt ch ar Btrl, onst char
*r)
int Caut
Const char *temP =
tr I;
int len 2=
hlenlt)

Count
ttj
temp +=Len

Yeturn Count:
}
ivnt
main C)

char Hr 1[looo, raioo;


Pintt(" Enter
aets Ctr4,
Bizeet
the trt
sting
(str)tin)s
: "):

Ptntt nter ecomd sting s):


Pyets

tratrcHPn(tra,
in='lo';
Pyitk The empt,No
n seiond 3trig is otcurene found \n.

int oceug olaur(tr14ra):

Ar2,0ceurs, tr):

O utput

Enter

Enter
te frt
the relond
pting

hing gCat
:Cat dag Cat

The thing cat' oteurs 2a ime in Cat dog Cat"


)
WRte a
<-Pogram
ile
to
Handling

wite and ead text into a


frle.

nclude<tio.h
vofd
man ()

FlLE * P;
Char
Nametaol:
Printt(\nEte e marne to Cveate ");

frl-fopen(t name,'w"

Ptntt(Fie dots not ceated !


"):

Printt ("Fle
Created
Auccgafully. );
Patc('a',tp):
Pate( 8' tr);
Putc ^e:
Nintt (" n Data wten fucystully.");
fose (PF);
fp-fpen (PName,"y),

Ptntf n Cant open frle ");


Print f (e"etc (Pr));
intf ( e" Jet (P));
Pintt (^"Jetc(t:
Acle (tP) ;
Output:

Enter fle mame to create g File -ty


Ele reated Buccegally.

Data wiitten guteyskily.

A Bc
wite wite and vead tert into a
a c-Proram to

bnay le gtng Pread() and Puite().

+ include< sto.h>
tvuct u dent

int yl;
Char name (2s);

void main ()

FtlE *$P:
chay ch;

tvut sudent

fp Popen ("shdert
-informatfon. txt", "w):
do

Pvint Roll no

Printf ("Alant to ad4 another data (Y "):

PrimtP( pata wittten Aucaslully \n


Pp fopen ("studet-
informatton.txt'

Rintf (Roll\t Name

while(iead(43 ,Mgeat
\n ")

(0),1.) >0)

Printdt3\n", 3roll,fname)3

fclope ()3

Roll No% 55
Name Kartkaya
Want to add another ddata

N
(y):
Data written sutcey fully 3

Roll Name
)11nitl
559 sosh
Karthikey,
(m) wvit a c-Program to oPy lontents oone #le to anothe

ele.

#includec stdiahs
Void main C)

FîLE *fPA,*P2;
char ch ;
mt(Enter the tet wth Q at exdg );
P -fopen ("Zample
1-tx*","w)
hgetchar():
wkle (eh-'a)

Pute (eh, tr);

Chgetchar)

Pate(hitra);

fdae (Pr):
PA-tePen(ample
1.txt"):
4pa -fofRn ("ampleitxt""w);

Pate (chtra);

Putc (ch,tra);
fclose (PP2);
fPa -fopen ("amplea.tx+",)

{
Patt (ch,stleut):

}
outPat:

Enter he text with @ at end ?


hello @
CoFRed text is :
hello

You might also like