CTSD Week 3
CTSD Week 3
STRUCTUREDI
DESIGN
Weck-3
Pre-lab:
Compls ts
MAk-
Stp3 pA Algtcham:i ithmandht: ps:/DurLIvww.NK:ation). t)heandurd ation. the Youare In-Lab:
hackerrank.cAlFlom/ctsd-lab-week-3
goorwchart
1.
simdurpleation maturity
MA stop
https:/is.gd/CTSDWEEK3
pint MA1R,PA, D Stat For working
interest (in amount
t23SC1101-COMPUTATIONAL
hat
pa formula:
years) help
input to me
for a
as financial
fixed
as
write
Maturityfrom deposits analyst
the aC
user. (FD)
Amountprogram at
a
Calculate thatbased bank. THINKING
=
Principal takes the on part
As
and
FOR
+(aTR*D
MAf PA Input TR +
(Principalprincipal
the
displayprincipal
your
the amount, job,
of
STRUCTURED
PrintMA
Stap Stast amount, you
maturity
* interest need DESIGN
Interest
amountinterest to
rate,
calculate
Rateusing
29 rate, and
*
23SC1101-COMPUTATIONAL THINKING
cORSTRUCRED DR
Program
Hincude cstdioh>
incude cstig:h
tt include matfhs
t incude StdlibhT
int main (U 4
int pa;
lon4(td'
float i;
, kpa);
an ("+f.&i);
float ma,
D5000
5600-0D00 00
28SC1101-COMPUTATIONAL THINKING FORSTRUCTURED DESIGN
budding mathematician, was studying the concept of area and perimeter. She was
2, Jenny, arectangular garden with a known length and width. Jenny wondered if she could find
given a derivea formula to calculate the
the area
without knowing the width. Can you help Jenny
and perimeter?
area
LINK: rectangle using only the length
of ahttps:/www.hackerrank.com/ctsd-lab-week-3
https:/is.gd/CTSDWVEEK3
(9Algorithm and Flowchart:
Algoithmn: Elolachast
Stast
:Stat
Tnput length i
stp 3 :AA*(%- ) înput perimeta
Stpu : print A A*(%- )
Step 5 iStop
print n
Stop
Cutprt :
31
01-COMPUTATIONAL THINKING FOR:
235C11
STRUCTURED DESG
Program:
Hicude < stdio:h>
1 include Stinq hT
+ inuude oth:hs
+ incude Sdlib>
int maint ) f
int
Sarg ("4-d", &);
int Pi
Sans ("4-d,&p);
intaj
Scanf ("td', &a);
a-(%-);
prntf (4-d',a);
vetusnoj
Sample Input and Output:
ame Snput
Sample culer
23SC1101-COMPUTATIONAL THINKING FOR STRUCTURED DESIGN
Aloithnm; Flochoast
: Stat Stast
Step 1
Input Side 1
Step3
Skpu : print H
înput side
Stcp5 : Stop
Hesqrt(s
npat : S.S print
33
Sange
oupu Sample maini (t { ZStingh>
include 4 Program
ude incude +includeStdio h>
13-000o 00
Sumae
înput
Input
("f'
priltfh),; -flbath; (y.Cod&sr',; inti incl<math.h>
and
Output:
z 23SC1101
St
dliboh
28SC110t-cOMPUTATIONAL THINKING FOR STRUCTURED DESIGN
DastLat
mathematician named Ale Alex loved solving mathematical
time, there was a across an ancient scroll that contained a secret
purzles One daY, Alex came mentionedthat by using
poblems calulate thesm of the first n natural numbers The scroll mumbers
and
Amla o number of natural without having
one oold find the sum of any given decided to test the
th formula Can you help
the la Alex was intriged and
at them un sum of the first n natural
manually uses the formmula to caleulate the
Alexinpleent
i a C programthat
nmbers
Instrctons:
n from the user and
calculates the sum of
that takes an input integer
We a C program
first n nahiral mbersusing the fomula
hesam (n(n+D)/2
INK: s wwhackerankeomct-abweck
hrtns gdCISDWEEK3
Alerithmand Flewchart
Aloithm Fochaat :
Steat1: Staxt Stat
35
put out Savge
S Snput
0 ple Sorn
Output: and Input Sample
etun
O;
("4d',Sum); pnif
(n*(n-1)) -Sum
Som; int
&n); (hd, Sonf
nint
main(){ int
LStdib.h inctude #
Lmatah incude #
sting-h> tirlude
TE FOR ING stdio.h) #incude
Program
23
225C1101-COMPUTATIONAL THINKING FOR STRUCTURED DESIGN
3 Once upon atime in a small town, there were two friends, Kavi and Jei, who were fascinated by
in mathematics, They loved exploring the hills and
the concept ofslopes calculate the slope of any given valleys around their town
and wondered how they could landscape, One sunny day,slone
aen a bill. Kavi and Jei discovered an ancient map that had the secret to finding the whilef
ine between two points. The map indicated that by using the coordinates of two points th
conld determine the slope of the line connecting them. Excited about their discovery, Kavi and Jei
decided to create a C program that could calculate the slope for any two points. They wanted to
share their program with others so that everyone could explore the slopes of various landscapes.
Can you help Kavi and Jei bring theiridea to life by implementing a Cprogram that calculates the
slope ofa line?
Instructions:
to enterthe coordinates oftwo points: (x1, yl) and (x2, y2). The
Write a Cprogramthat prompts the user
programshouldthen
calculate the slope of the line connecting these points using the formula:
slope =(y2 -yl) / (x2 - xl)
Finally, the program should display the calculated slope to the user.
LINK:https://www.hackerrank.com/ctsd-lab-week-3
https://is.gd/CTSDWEEK3
Algorithm and Flowchart:
Flonchast:
Alnottim
1 Stast
Stcp Shat
înput X,X
Tnput x;
Stp 3 : lope
Input y
Tnput Xa
Inputya
print Slope
ctop 37
incude +
Samgle Sompl
îput
6e
Sample
siopeint j int main
prit Sepe =
int
incude #incl
LSt
ude
dio:Prhograms
3
Input
Xi
Cuput
18
and
(d, f 23SC1101-CO
Btdlibhs LIDath h>
(0
Output:
36
{
sloge);
1)
ORSTRUCtPEU FO
235C1101-COMPUTATIONAL THINKING FOR STRUCTURED DESIGN
(-x)+
dsance- Sqrt ()Input y
psint distance
print disance
oupu : distayce
Stp
39
Yetusn O: disionce;
-floot main(0{ int inctude + include
Stdlib.hs irctude t Program
Sample
("+-f,dsance);
pintí Xiy,,9) int
cutpnRam pe Sampl
înpat
1u3
e
Input
and
Output:
Sring.h d2io-h
<St23SC1101-COMPUTATIONAL
THINKING
FOR
STRIUCTURR0t
Stp
Sip5: Stp3 Algoithm: Flowchart:
Algorithmand
LINK: heightcalculuse ates
htps://ww.hackerrank.com/ctsd-lab-week-3
IputD,R:
H 1 the
Imagi
of heigpersOn
inverse ht
ne at is
a a
1. of
the
Session:
Skil Date
Sesson:
of
Snpt'D coconuts?
based coconutsare
the
(Sto Staat on a
t(Hint:
he C
write
hanging
from Session: DESIGN
ratioprogram
positioned
you
it.
of There.
the can that
41
pintf );arge arbagte; flaat D;
inctuLShiidemtethu#.ndehing.cL
Sthtusdeio.hs
Program:
Sample
Input
YetunOj
(4ange float Hj
-
and
Output: atano) 235C1 t
83.1l|
592)
StepR:1hpt obStep 1: Flowchart:
Agasitfm Algorithmand
LINK:ht ps:/www.hhtackertps:/riasnk..gd/cCom/TSDWEEK3
ctsd-lab-weck-3 2.
Swapping chests,cach findto Ina
values. them Alex containing
gemstones faraway
Stot byand
writing Bella the
valuable
inside
kingdom,
235C1101-COMPUTATIONAL
gemstones,
realized
a treasures.
the
C
program they chests.
b To
a two
uniqueWhile
treasure
thatcouldfulfill
However,
exploring
gemstone.
takes usetheir hunters
a
the thirdquest a
magical a THINKING
values Curiosity named
variabletheirand mysterious
restore
enchantment
of Alex
over,
took FOR
the and cave, and
arithmetic the
STRUCTURED
gemstones
treasures they Bella
prevented they
and
embarked
stumbled
ol operations.
input,
as to DESIGN
decided
them upon on
andrightfulfrom daring two
a
Can to
swap Swap
youdirectlytreasure
chests, quest
their help the
43
ame6cuptu Snput
Sanepe and("AficY
Sample
Input pittf Il
Ipin'If int Stdioh>
inctudeProgram:
#
5 hetusnoi port
Sonf int<soioh>
ab,*p.aj moth:hs
intutde
mainincHe
(-d\n
5 6 ("ec
Output:
(d ()
fose f
Sigopingn); d\n Sno 1-d,
ppirgnn; &a,
"); P,
b); 8
Er
3.
ht LE de
235C1101-cOMPUTATIONAL THINKING FOR STRUCTURED DESIGK
young
architect, was working on designing a cylindrical water tank for a new
building.to
As sheawas finalizing the plans, she needed to calculate the surface area of the cylinder
3, Emily.
determinethe amount of material required for its construction, However, she was unsure of the
exact formula
program
and the steps involved in the calculation. Can you help Emily by writing a C
that assists her in calculating the surface area of acylinder?( Surface Area 2r+ 2rh)
INK:https://www.hackerrank.com/ctsd-lab-weck-3
https://is.gd/CTSDWEEK3
Algorithm and Flowchart:
lochaot
Step1: Stast Stasit
Stp 3 At2*3u*Y
+2*3h
pent A
A*3|*TY
Step5 : tp 3u*h
pirt A
45
23SC110: GFOR STTRUCRE
include
Program: Stdio:hs
inctude LShing-hs
# math.h
tt include /
44 incude Stdlíb:hs
int main () f
Sarf ("+4",&);
int h;
Compe înpt
268
Samele outpt
STRUCTURED DECies
225C1101-cOMPUTATIONALTHINKING FOR
polygon-shaped fountain
design a garden with a beautiful determine the appropriate
architect who wantsto can
is an
4 Hemanth Henceds to calculatethe area of
the polygon so that hecalculates the area of a regular
center. writing a C program that
atits fountain. Help Hemanth by of each side.( Area (numSides*
the sides and the length
for
size given the number of numSides))
polygon when /(4 * tan(n/
sidelength * sideLength)
INK: htps:/www.hackerrank.com'ctsd-lab-weck-3
https://is.gd/CTSDWEEK3
Flaochat:
Ahovthm:
Stat
Stat
Sip2 :înput
tana)rput n/
47
235C11
FOR STRUCTURED
Hictude
Program: stdio+hs
include zStrinq.hs
# inctude ZStdlib-h
int main() f
Sorf(4d', &n);
Sint S;
Sorf (hd, &s);
netuan o;
3
Sample Input and Output:
Sompe Dnpd
4 5
Samje outút
25.0)9919
235C1101-COMPUTATIONAL THINKING FOR STRUCTURED DESIGN
loves ice cream cones and wants to decorate the surface of her
5. Prathima
colorful stickers. To know how many stickers she necds, she wantsfavorite ice cream cone
with to
Help Prathima by writing a Cprogram that calculates the calculate the surface
area of the cone. height surface arca of a cone
when given the radius of the base and theslant
(Surface Area*r*(r+)
https:/ww.hackerank.com/ctsd lab-weck-3
https://is.gd/CTSDWEEK3
Algorithm and Flowchart:
loithm: lonchost
Stat
Step 1 Stast
pint Asea
49
q6-939%51
opt Sompe
îrput Cange2-65
Output: and Input Sample
Sa); (4' ietusn
pr0;rms
áL); ("td lant
Ljint
Stdibhs include
L t
Lmath.h) include +
cSdiohs include #
Program:
UE FOR ING
235C1101-COMP