algorithm lab Write: 1. An algorithm that gets three data values x, y, and z as
ID: 3694555 • Letter: A
Question
algorithm lab
Write: 1. An algorithm that gets three data values x, y, and z as input and outputs the average of those three values.
2. An algorithm that gets the radius r of a circle as input. Its output is both the circumference and the area of a circle of radius r.
3. An algorithm that inputs the value of a number x. The algorithm then employs an if/then/else statement that sets the variable y to the value 1 if x 0. However, if x < 0, then the statement should set y to the value 2.
4. An algorithm that is given the length and width, in feet, of a rectangular carpet and determines its total cost given that the material cost is $23/square yard.
5. Modify the previous algorithm such that inputs the length and width, in feet, of a rectangular carpet and the price of the carpet in $/square yard. It then prints out a message indicating the cost of the carpet as well as a message indicating if we can afford to purchase this carpet, given that our total budget for carpeting is $500.
6. Write an algorithm that adds up a sequence of twenty numbers and outputs the sum of the numbers as well as the average of the numbers. (Your algorithm MUST use the repetition control structure to read in and process the inputs.)
Explanation / Answer
1)
Get values of x,y and z
set average to (x+y+z)/3
Print "the average of three numbers is " ,average
stop
2)
Get value for r
Set circumsference to 2*3.14*r
Set area to 3.14*r* r
Print ”Circumference is ”+circumsference
Print ”Area is ”+area
Stop
3)
Get value of number x
if x>=0 Then
Set the value of y to 1
Else
Set the value of y to 2
stop
4)
Set area to length*width
Set area into yard area*0.33*0.33
set price to area*23.
Print "Price of carpet will be ",price
5)
Get length and width
Set area to length*width
Set area into yard area*0.33*0.33
set price to area*23.
If price <=500 Then
Print "Carpet is affordable "
Else
Print "Carpet is not affordable"
stop
6)
1) Set i to 0
2) Repeat step 3 to 5 untill i=20
3) Get value of n
4) Set sum to sum+n.
5) Set i to i+1
6) Set average to sum/20
7) Print "average is ",average
8) Print "Sum is ", sum
9) stop
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.