Vous êtes sur la page 1sur 3

//Program that allows the user to calculate the total profit

//from the total amount of sales.


module main()
Declare Real totalSales
Declare Real profit
Display "Please enter the rpojected amount of total sales"
Input totalSales
set profit = totalSales * 0.23
Display "Your total profit is",profit
End module
//Program that allows users to find the number of acres from the
//amount of square feet entered.
module main()
Declare Real acres
Declare Real tract
Display "Enter the total number of square feet in your tract."
Input tract
Set acres = tract/43560
Display "The total number of acres in your tract of land
is",acres
End module
//Program that shows the minimum amount of hotdogs and buns are
//required along with the number of hotdogs and buns are left over.
module main()
Call hotdogsFinder()
End main
Module hotdogsFinder()
Declare Integer people
Declare Integer hotdogs
Declare Integer minBun
Declare Integer minHotdog
Display "Enter the number of people attending the event"
Input people
Display "Enter amount of hotdogs to be given out"
Input hotdogs
Set hotPackage = 10
Set bunPackage = 8
Set minHotdog = people*hotdogs/hotPackage
Set minBun = people*hotdogs/bunPackage
Set leftOverb =
Set leftOverh = people*hotdogs/bunPackage
End Module hotdogsFinder
//Algorith Workbench 2
Module Main()
Declare Integer n
Display "Enter n"
Input n
Call trafficSign(n)
End Main
Module trafficSign(Integer n)
If n > 0
Display "No Parking"
Call trafficSign(n-1)
End If
End Module
//Program 4
//This program will accept an integer as an arguement
//and return the sum of all integers from 1 to the integer passed.
Module Main()
Declare Integer n
Input n
Call getSum(n)
Display n
End Main
//If n=1(The base case), the program will stop the
//recursion, if n != 1 then the program will
//continue on subtracting 1 from n.
Function getSum(Integer n)
If n == 1
Return n
else
If n > 1 Then
Return (n + getSum(n - 1))
End Function

//Program 5
//This program will use recursion to raise
//a number to a power.
Module Main()
//Variables n and y hold values the users want to input
//While the answer variable holds the value from the function
//toThePower
Declare Integer n, y
Declare Integer answer
Display "Enter a base value"
Input n
Display "Enter a value for the exponent"
Input y
Set answer = toThePower(n, y)
Display "The answer of",n,"^",y,"is:",answer
End Main
//Function toThePower iterates y - 1 to get the next power
//the base variable needs to complete the problem.
Function toThePower(Integer n, y)
If y == 1 Then
Return n
Else
If y == 0 Then
Return 1
Else
If y > 1 Then
Return n * toThePower(n, y - 1)
End If
End Function toThePower

3*3,2
9
9*3,1
27,1
3^3
3*3*3

Vous aimerez peut-être aussi