Here are the list of sample problem and algorithm in programming language
1. Write a program that reads three numbers A, B, and C, and prints the value of the largest. Values are assumed to be distinct.
Algorithm:
1. Input data values
a. Read (A, B, C)
2. Determine largest value
If A>B and A>C
Then max ß A
End if
If B>A and B>C
Then max ß B
End if
If C>A and B>C
Then max ß C
End if
3. Print largest value
Write (“Largest value is “, max)
4. Finished [halt]
2. Write a program that determines the largest of three inputs. Largest contains the largest value encountered so far. Current denotes the current number being answered. All value is integer.
Algorithm:
1. Read first number
a. Read (largest)
2. Read second number
b. Read (current)
3. Update largest number so far
If current>largest
Then Largest ß current
End if
4. Read third number
Read (current)
5. Update largest number so far
If current>largest
Then Largest ß current
End if
6. Display largest value
Write (largest)
7. Finished [halt]
3. The amount of apples per kilos is equal to 50 pesos. If the customer buys 3 or more kilos of apples, 5 peso will be discounted for every kilo. Determine the total cost of apples purchased
Algorithm:
1. Enter the amount of apples
c. Read (Read quality of apples purchased in kilos)
2. Compute the total of apples
If quality of apples is equal or more than three kilos
Then compute cost of apples with discount
Else
Compute cost of apples without discount
End if
3. Display the total cost of apples
Write (“Total cost of apples “, apples)
4. Finished [halt]
4. Given individual marks in three aspects of a year’s work in a course (Laboratory_work, midterm, exam, and final) for a student name NAME, this algorithm computes the final grade with weighting of 20, 30, and 50 percent, respectively. The printed output gives the students name, individual marks, and a final grade.
Algorithm:
1. Read first number
a. Read (NAME, Laboratory work, midterm exam, final exam)
2. Compute the final grade
a. Grade ß 0.20 * Laboratory work + 0.30 * midterm exam + 0.50 * final exam.
3. Display result
a. Student name
b. Laboratory mark
c. Midterm exam
d. Final exam
e. Final grade
4. Finished [halt]
0 comments:
Post a Comment