1 .
)ah n avi 1h urs
day '\ 5:35
JT
0 r7 SJ ), SH ILPA 04 -09-20
2 4 HO '\
1 . W rite a pr og ram
to rea d an d print
2 . W rite a pr og ram array eleme nts( usi
to initialize an arr ng index and using
3. W rite a pr og ra ay wit h the first 10 address)
m to fin d the maxim nat ural numbers and
u m an print the elements.
4 . W rit e a pr og ram d mi nim um elements in
to ca lculate the sum an array of integers.
and average of ele me
nts in an array.
V ~ • Q tcJ
,:.:, n 1 , Ja\ ,navi '\9- 09
-20 24 , 7:28
1. W rit e a pr og ram t::?
. the ele me nts
to _reve,s
.
2. nt e a p ro g ram to 5e arch fo
e ·r ofI me an arr ay.
nt in an arr ay and pri
r a sp ec1 nt its index if fou nd
W . . f int ic
egeers
e
3 . W rite a p ro gr in ascendi.ng orde r
am to so rt a; t:~ a~
4 W rit e a pro g ram
to merg r;a ys int o a single
. arr ay.
5. W rite a p ro gr un t the oc cu rre nc f each element ,na n
am t o co es o array.
6 W rit e a pr og ram t o rem ov e d 1· ate eleme nts trorn an arr
· up ic ay.
7 . W rite a pro gram t fin d the sec on d ,arg est e\ernent in
·
an arra y.
8 W rite a pro gr am o
to ch eck ,f. an arr ay is a pal indrome. .
.
m to find the trans e of a given 2D array
9 . W rite a pro gr a po s
(ma tnx).
·· ,
r JT T, Ja hnavi 19-09-2 024 17:28
1. WA P t o g et the positio n of a substr·i ng in a st ri ng 1
2. V\/AP to rever·se t he given string
3. WAP to rever·se t he given line
r JT T, Ja hnavi 19 -0 9-2024 17:29
1. Write a prog ram t o remove duplica te charac ters from a string .
2. Write a prog ram t o ch eck if two strings are anagra ms of each ot her.
3. W rite a program to check if a given string is a palindr ome or not.
4 . W rit e a p rogram to so rt an arra~ f strings in lexicog raphic (dictio nary) order.
Pract ice Questi o ns:
1. You are given a strin g, str.
You need t o find the score o f str as per t he fo ll ow ing ru les:
1) For each pal indrom e o f leng th 4 in str, add 5 to t he score
~,-1,-l 1 n t·,-, t-1-.p crnrP
• -- ~ ,. , 1 1 ' ~jJ j ll.
per· t.l1 e f II . I
You nee d to fi nd t he sco re of str- as o ·owin g ru es:
1) Fo r ea ch pal ind rom e of leng
th 4 in sti-, add s to the score
in str, add 1Oto the score
2) Fo r eac h pa lind mm e of length 5
Lt
palindrome must be
n t hat palindr o mes can ove rl ap within str. However, the characters of the
It is give of the string.
(i.e. they must NOT wrap around the end
co ntin uo us a nd mus t NOT be circ ular
Ou t p ut t he fr"'. a/ va lu e of score.
Not es:
~ype a mes sa ge
-
lt is give n tha t pali ndr ome s can ove rlap
con tinu ous and rnus t NOT be circ ul .
w ithin str Ho . I
C I . weve,, tie characters of the palindrome must
a, i.e. t ,ey mus t NOT wra p around the end be
of the string.
Ou tpu t the fina l va lue of sc01·e .
Not es:
• A pa lind rom e is a wor d, phra se, or seq
uen ce that reads the same backwards as forw
ards. Examples
of pal ind rom es are wor ds like "rr1adan1
", "racecar" , "abCba" and "aBccBa", and "ABB
A"
• Pa lin dro m es are cas e-se nsit ive in this
prob lem (e.g. "Ma dam " and "ABCcba " are NOT
palindromes)
• Th e sco re is initi ally 0
• T h e re are no w hite spa ces in str.
. C m to rem ove from last occ urre nce of a wor
2. Vvr-i r.e a pro g ra d in given string
Exa m p le
Inp ut
. . _
Inp ut strin g. 1 am - pro gra mm er. I lear n at Cod efor win .
a
Inp ut v1ord to rern01e: I
Output
String after removi ng last occurrence of 'I':
I am a pmgrammer. learn at Codeforwin
3. Write a C program to replace first occurrence of a character with another character in a st ri n g .
Example
Input
Input string: I love programm ing .
Input charact er to replace: .
Input character to replace with: !
Output
String after rep lacing '.' with '!': I love programm ing!
r JT T, Jahnavi 19-09-2024 17:29
Practice Questions on Structures
1. Write a progra!TI to define a structure called Student with members: name, age, and grade. Create
an instance of this str-ucture and take input from the user for each member, t hen print the values.
2. Create a strncture Book with members: title, author, and price. Create an array of 5 books and take
input from t he user for each book's details. Finally, print the details of all books.
3. Create a str·ucture Employee with members id, name, and salary. Write a function t hat takes an
employee strnctur·e as an ar·gume nt and p rints its members.
4. Define a str·ucture to hold th e product sales information, stru ctu re wi ll contain the product_lD and
total_sa les_amount.
Write a prog1·an1 that accepts mult iple product records (product_lD and total_sales_amount) and
print s t hem in decreasing order· of tot~sal~s-:-amount. .
In case there are multiple records pertarnrng to the same pmduct_rd, the prog ram should choose
a sin g le record contai~ing the highest total_sales_amou nt.
Program should take multiple line input.
Each subsequent line of input will con tain a Product record, that is, a pro duct_lD and
total_sa les_a mount (separated by a hyphen).
The output should consist of the combinat io n of product_lD and corresponding
to tal_sa lts_a mount in decreasing order of score.
Sa rnpl e lriput:
P1001 -2Jf;
Sample In p u
t
P1001-200
r 1002-1so
P1 0 0 3 -3 0 0
p 1 0 0 1 -1 0 0
p1 0 0 2 -2 0 0
P 1 0 0 3 -5 0
P 1 0 0 1 -5 0
r1 002-2so
Sa m ple O u
tp ut
P100 3 -3 0 0
P100 2 -2 5 0
p1001 -2 0 0
t V
Oo
co BJ
1. Write a prog ra m that re moves duplicate words from a pipe-separated stri ng.
For example, t he input a pplelora ng e lba nana lapplelgra pe sho uld return apple[orangelbananalgrap e
2. Write a prog ram t hat Finds the u niqu e words from a pipe-separated string .
3. Write a progra m t hat so rts the words by thei r Iength in asce nd ing ord er in a pipe-separated string
4. W rite a prog ram t hat reve rses each ind ividua l word in a pipe -separated stri ng whi le keeping the
o rigina l order o f w ords. Fo r examp le, th e in put applel ban analgra pe shou ld return
elppajananab jeparg .
s. W rite a p rog ram that splits a pipe'--:~ep arated str1n g into words and 1·eve rs es the order of the words.
For examp le, t he input app lejba nana !g rape loi-ang e shou ld return oran gelgrap~l bananalapp le.
r7 n T, Jahna vi 24-09 -2024 76:13
Practice Quest io ns on Strings:
f om the string to fo rrn a new stri ng . For
I
.
1 De lete A lte rn at ing Characters alternatin
. .
Given .
a string s, delete g cha racte rs r
· tf etc ., characte rs.
exa mp Ie, d elet e t he second, fo urt h, si x 1,
Exam p le:
In puts = "abcdef"
O utp ut "ace"
Input: s = "abcdef"
Output: "ace"
2. Remove Duplicate Consecutive Characters
Give n a string s, remove consecutive duplicate characters until no consecutive duplicates
remain. For example, from "abbaccd", remove "bb" and "cc" in separate operations.
Example:
In put: s = "abbaccd"
Output: "d"
Initial String: "abbaccd" a
First Pass:
Find and remove "bbv.
The string becomes "aaccd".- ,.,..
Second Pass: <•.• ' .,,,.
Find and re move "aa".
The string becomes "ccd".
Third Pass:
Find and remove "cc".
The string becomes "d".
Final String: "d"
3 Given a strings, delete pairs of consecutive vowels (like "ae", "io", etc.). Return the number of
deletions made.
Example:
lnn11t· c; = "hp;:i11tif11I"
Example:
Input: s = "b ea ut iful"
)
Ou tp ut: 1 (d ele tes "ea"
e Anag ram s
4. Check if All Words Ar k·
rated words a d I words are anagram s of
each other.
Inp ut co mm a sepen, lse. n , c iec if all the
ot he vise fa
Retu rn tru e if th ey are,
Exampl e:
, "d us t", "styd y"J
Inp ut ["d us ty ", "st ud y"
Ou tput: false
er anagra ms nor identical to any other
vvo rd s, fin d all wo rd s that are unique (neith
.:i. Gi ve n a li~ t of
wo rd 111 th e 11s t).
exampl e: "cba"J
·~oL..t: ~"l ist en ", "silen
t", "hello ", "worl d", "abc",
"]
8u :o ur: ["h ello ", "v,1or ld
er from the
ep ara ted lists of in teg ers and finds which int eg
6 '.', r,;: e a pr og ra m th
at takes two comma-s its co unt.
rre nc e in the se co nd list. Print that integer and
occu
"r s: I st has rh e highes t
Sa,.,,..p 1e 111 put:
=- :er rr-e fir st 11s t of integer
s (comma-se parated): 5,
-separa
3, 4,6
ted): 5,4,2, 1,4,3,3,2, 5,3
I
:~ '.:f r r~e second
lis t of integers (com ma
:;; ~- : e CI.Jtr,ut
eqer Nin
-se pa rated lis ts of int eqers as input. For each int
,..;,,:,r;ra ,. .,. , tri at takt-s tv;
o com ma
- !.' rt: :~
7 Write a p rog ram that takes two co mma -se parat ed lists o f int egers as input. For each integer N in
t he first list, calculate the su m of its o ccurre nces in t h e second list and print N-S fo r each integer.
Sample inp ut:
Ent e r t he fi rst list of integers (comma - separate d): 5, 3, 4,6
Enter the second list of integers (comma- sepa rated ): 5,4,2,1,4,3,3,2,5,3
Sample Out put
5-10
4-8
3-9
6-0
t7 n T, Jahnavi 26-09-2024 09:4 3
2.take n lines of input ,input a cha racte r and input a string. Sea rc h character and word in each line,
print the position and sum the position.
3.input an array with n elements from 1,2,3, ....... n. Find the missing element.
4.input a sent ence and capitalize last letter of each word
5.input a string (wo rd) and delete adjacent duplicate characters .
1
r7 1 I, Ja hn avi 26-09-2024 09:43
2..take n li nes of input ,input a character and in put a string. Search character and word in each line,
print t he positio n and ,sum th e position.
3.input an array wi th n ele ments from 1,2,3,....... n. Find the missing eleme nt.
4.input a sentence and ca pita\ize last letter of each word
5.input a string(wo rd) and delete adjace nt du plicate cha racters.
..,... "F'"=----
- · =~--=-~:-=== ~ - - ...,... -
~ n T, Jahn avi 26-09-2024 09:38
1.input 2 arrays, merge them ,remove even num bers and so rt them.
-:-;pe a message At? Q