Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
32 views

Algorithms and Computational Thinking With Functions

The document describes algorithms for common computational tasks like finding the difference, product, average, and volume calculations for different shapes. It includes algorithms to convert between seconds to minutes, pints to liters, and calculating speed from time and distance traveled. The algorithms use functions and conditionals to break problems down into logical steps and calculate the desired output.

Uploaded by

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

Algorithms and Computational Thinking With Functions

The document describes algorithms for common computational tasks like finding the difference, product, average, and volume calculations for different shapes. It includes algorithms to convert between seconds to minutes, pints to liters, and calculating speed from time and distance traveled. The algorithms use functions and conditionals to break problems down into logical steps and calculate the desired output.

Uploaded by

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

Algorithms and Computational Thinking

Dan Kimberley 10GB


Find the difference between two numbers.
START
FUNCTION MAIN():
INPUT NUM1
INPUT NUM2
CALL GETDIF(NUM1,NUM2)
PRINT DIF
FUNCTION GETDIF(NUM1,NUM2):
DIF = NUM2 NUM1
RETURN DIF
CALL MAIN()
PRINT DIF
END
Find the product of two numbers (this means to multiply the two numbers).

START
FUNCTION MAIN():
INPUT NUM1
INPUT NUM2
CALL PRODUCT(NUM1,NUM2)
PRINT RES
FUNCTION PRODUCT(NUM1,NUM2):
RES = NUM1 * NUM2
RETURN RES
CALL MAIN()
END
Change the time in seconds to minutes
START
FUNCTION MAIN():
INPUT SECS
CALL SECSTOMINS(SECS)
PRINT RES

FUNCTION SECSTOMINS(SECS):
RES = SECS / 60
RETURN RES
CALL MAIN()
END
Change a volume in pints to litres (there are 2.2 pints in every litre).
START
FUNCTION MAIN():
INPUT PINTS
CALL TOPINTS(PINTS)
PRINT RES
FUNCTION TOPINTS(PINTS):
RES = PINTS / 2.2
RETURN RES
CALL MAIN()
END
Find the volume of a cone given its diameter and height
START
FUNCTION MAIN():
INPUT DIAMETER
INPUT HEIGHT
CALL GETVOL(DIAMETER,HEIGHT)
PRINT VOL
FUNCTION GETVOL():
RAD = DIAMETER / 2
VOL = PI * RAD ^ 2 * (HEIGHT / 3)
RETURN VOL
CALL MAIN()
END
To find the volume of a cube given the length of a side.
START
FUNCTION MAIN():
INPUT LENGTH
CALL GETCUBE(HEIGHT)

PRINT CUBE
FUNCTION GETCUBE(LENGTH):
CUBE = LENGTH ^ 3
RETURN CUBE
CALL MAIN()
END
To find the volume of a pyramid, given the length and breadth of its base and its height.
START
FUNCTION MAIN():
INPUT WIDTH
INPUT LENGTH
INPUT HEIGHT
CALL GETVOL(WIDTH,LENGTH,HEIGHT)
PRINT RES
FUNCTION GETVOL(WIDTH,LENGTH,HEIGHT):
RES = (WIDTH * LENGTH * HEIGHT) / 3
RETURN RES
CALL MAIN()
END
To find the average speed of a car given the journey time and the distance travelled.
START
FUNCTION MAIN():
INPUT TIME
INPUT DISTANCE
CALL GETSPEED(TIME,DISTANCE)
PRINT SPEED
FUNCTION GETSPEED(TIME,DISTANCE):
SPEED = DISTANCE / TIME
RETURN SPEED
CALL MAIN()
END
Find the average of four numbers
START
FUNCTION MAIN():

INPUT NUM1
INPUT NUM2
INPUT NUM3
INPUT NUM4
CALL GETAV(NUM1,NUM2,NUM3,NUM4)
PRINT AVERAGE
FUNCTION GETAV(NUM1,NUM2,NUM3,NUM4):
AVERAGE = (NUM1 + NUM2 + NUM3 + NUM4) / 4
RETURN AVERAGE
CALL MAIN()
END
Find the largest of four numbers
START
INPUT NUM1
INPUT NUM2
INPUT NUM3
INPUT NUM4
IF NUM1 IS GREATER THAN NUM2 AND NUM3 AND NUM4 THEN PRINT NUM1
IF NUM2 IS GREATER THAN NUM1 AND NUM3 AND NUM4 THEN PRINT NUM1
IF NUM3 IS GREATER THAN NUM1 AND NUM2 AND NUM4 THEN PRINT NUM1
IF NUM4 IS GREATER THAN NUM1 AND NUM2 AND NUM3 THEN PRINT NUM1
END
Find the smallest of four numbers
START
INPUT NUM1
INPUT NUM2
INPUT NUM3
INPUT NUM4
IF NUM1 IS LESS THAN NUM2 AND NUM3 AND NUM4 THEN PRINT NUM1
IF NUM2 IS LESS THAN NUM1 AND NUM3 AND NUM4 THEN PRINT NUM1
IF NUM3 IS LESS THAN NUM1 AND NUM2 AND NUM4 THEN PRINT NUM1
IF NUM4 IS LESS THAN NUM1 AND NUM2 AND NUM3 THEN PRINT NUM1
END

You might also like