0% found this document useful (0 votes)
78 views23 pages

CTSD Week 3

The document discusses computational thinking for structured design and provides examples of calculating maturity amounts for fixed deposits using formulas that take the principal amount, interest rate, and years as input. It also includes sample C code to calculate maturity amounts and output the principal amount, interest amount, and total maturity amount. The document suggests helping a student named Jenny derive formulas to calculate the area and perimeter of a rectangle using only the length.
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)
78 views23 pages

CTSD Week 3

The document discusses computational thinking for structured design and provides examples of calculating maturity amounts for fixed deposits using formulas that take the principal amount, interest rate, and years as input. It also includes sample C code to calculate maturity amounts and output the principal amount, interest amount, and total maturity amount. The document suggests helping a student named Jenny derive formulas to calculate the area and perimeter of a rectangle using only the length.
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/ 23

23sC1101-cOMPUTATIONAL THINKING FOR

STRUCTUREDI
DESIGN
Weck-3

Dateof the Session: Time of the Session:

Pre-lab:

1 List the various data types supported by the C programming language.


iou doto tpe Cae
loot (tf) ,couble
2.
int (-i:d)
Cha (-) (orgflocd)u
What are the characteristics and memory requirements of different data types in
the Cprogramminy
long int u bytey
language?
int- u byec
float - tbyto double( long toct) -Ebyhy
Cha Ibyte, lorg long int bpty
3. Explore the concept of short-circuit evaluation in C, specifically in relation to logical
and |). operators (&&

4. How do you declare and initialize a pointer variable in C? Provide an example.


pointe de lorsation,oe only decaoe
-tte ante but do not AriialieT0 declo
we we (*) dereference perctoy be-foX ik nare
5. Discuss
class?
the significance of the "static" storage class in C. How is it different from the "auto'" storage
Static:
Tt de-foult Llae is rer0.The Cope is loal
Te Vaue is Same even aftey fen Chon Complek
xection.
eto:
defult lae ii oao bage Ltalie.7f s
loal.Te al is (ot once tthe
bie funchon 28

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,

Sample Input and Output:

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

Develop a Cprogram that computes the hypotenuse of tenter


a right-angled triangle given the
3. perpendicular sides. Prompt the user to the lengths and display the
lengths of itstwo theorem: HypotenuseSidel? +Side22y
sult. (Pythagorean
httos/A Ir.hackerank.comctsd-lab-weck-3
htps:/s.gd'cCTSDWVEEK3

Algorithm and Flowechart

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

Step: înput n'

Step u:print Sum


Stop
prínt sum

Cuiput : Sum stop

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

treasure hunt adventure, following a map with hidden


and Kavi are on an exciting They want to calculate the distance bctween two
Ravi
3 treasures lcated at different coordinates,
to determmine how far apart they are. Can you help them by writing a Cprogram that
treasresthiscalculation?
performs
Instrxtions
the userto enter the coordinates of two treasures: Treasure
Wnite a Cprogramthat pronpts (x. y) Calculate the distance between the
Tresure B. The coondinates should be in the form
Aand distance fomula:
reasures using the
distance =sqrt(x2 -xly2 +(y2 -yly2)
output a message indicating how far apart the treasures are.
Finally,
ctsd-lab-week-3
LINK btts www.hackerrank.com
https/isgd CTSDWEEK3
Algorithm and Flowchart

Aloitim: Eloul chatt :


Stp1: Stat 8taat

(-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:

https::/is.gd/CTSDWEEK3 the the scenario a


Angle : Staot coconuts anglestandiof
tangent
ng
235C1101-COMPUTATIONAL
"H"
at where at
to meters
a
the which distancethere
<-atan("b) function
distance the from
(atan()person the "D" of isa
from ground. coconut
in meters
should
the C) THINKING
tree
tree.) toaimCould away
determine with
in
you from FOR
order multiple
the
the please
to
STRUCTURED

Anglpinet [lolchost angle hit help


tree.
coconuts
the The
Time

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;

avea= 2*3.u4 *3.uyh:


printf("4
eturn o;

Sample Input and Output:

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

Algorithm and Flowchart:

Flaochat:
Ahovthm:
Stat
Stat
Sip2 :înput
tana)rput n/

Stp Area Irput s


Stcp 5 : Stop
tor()
pit Aea

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

Stp u:pent rea


step 5: step

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

You might also like