PANGASINAN STATE UNIVERSITY
URDANETA CITY CAMPUS
COLLEGE OF ENGINEERING AND ARCHITECTURE
DEPARTMENT OF MECHANICAL ENGINEERING
ACADEMIC YEAR 2024-2025, FIRST SEMESTER
LABORATORY REPORT
IN
COMPUTER FUNDAMENTALS AND
PROGRAMMING
Submitted by: Submitted to:
Your Complete Name Engr. Miguel Albert D. Calizar
2 LABORATORY BS MECHANICAL ENGINEERING
COMPUTER FUNDAMENTALS AND PROGRAMMING
REPORT
LABORATORY ACTIVITY NO. 09
Algorithm
OBJECTIVE: To write the algorithms for each Programming Activities.
PROCEDURE:
1. List down the algorithm of your Display Programming Activity.
2. List down the algorithm of your User Input Programming Activity.
3. List down the algorithm of your Conditional Statements – If-else and
Switch Case.
4. List down the algorithm of your Looping Statements – For loop, While
Loop, and Do…While Loop.
5. List down the algorithm of your Array Programming.
OUTPUT:
1. Step 1: Start
Step 2: Read Lab 9, Name, Adress, Age , Sex, Course, Subject, Year, and
Schedule
Step 3: Display Lab 9, Name, Adress, Age , Sex, Course, Subject, Year, and
Schedule
Step 4: The program then ends.
2. Step 1: Start
Step 2: Input User Information: Get Lab number, Name, Address, Age, Sex,
Course, Subjects, Year, and Schedule.
Step 3: Display User Information: Get Lab number, Name, Address, Age, Sex,
Course, Subjects, Year, and Schedule.
Step 4: End
3. Step 1: Start
Step 2: Input two numbers, a and b
Step 3: Choose an operation from the following options: Sum, Difference,
Product, Quotient, Modulus, Power
PANGASINAN STATE REGION’S PREMIER UNIVERSITY
3 LABORATORY BS MECHANICAL ENGINEERING
COMPUTER FUNDAMENTALS AND PROGRAMMING
REPORT
Step 4: Let e represent the sum, f represent the difference, g represent the
product, h represent the quotient, i represent the modulus, and k represent
the power.
Step 5: If the chosen operation is e, calculate the Sum: a + b
Step 6: Print the Sum
Step 7: If the chosen operation is f, calculate the Difference: a - b
Step 8: Print the Difference
Step 9: If the chosen operation is g, calculate the Product: a * b
Step 10: Print the Product
Step 11: If the chosen operation is h, calculate the Quotient: a / b
Step 12: Print the Quotient
Step 13: If the chosen operation is i, calculate the Modulus: a % b
Step 14: Print the Modulus
Step 15: If the chosen operation is k, calculate the Power: a ** b
Step 16: Print the Power
Step 17: End if;
Step 18: End
4. If Else:
Step !: Start
Step 2: Input a number x.
Step 3: If x > 0: Print "The number is positive".
Step 4: Else If x < 0: Print "The number is negative".
Step 5: Else: Print "The number is zero".
Step 6: End.
Switch Case
Simple Step-by-Step Algorithm:
Step 1: Start.
Step 2: Input two numbers, a and b.
Step 3: Calculate the sum: result = a + b.
Step 4: Switch on the value of result:
PANGASINAN STATE REGION’S PREMIER UNIVERSITY
4 LABORATORY BS MECHANICAL ENGINEERING
COMPUTER FUNDAMENTALS AND PROGRAMMING
REPORT
Case 0: If result == 0, print "The sum is zero".
Case 1: If result == 1, print "The sum is small positive".
Case -1: If result == -1, print "The sum is small negative".
Default: If result is any other number, print "The sum is neither 0, 1, nor -1".
Step 5: End
5. For Loop
Step 1: Start the program.
Step 2: Initialize the sum variable sum = 0 to store the cumulative sum.
Step 3: Initialize the loop control variable i = 1.
Step 4: Set the loop condition: i <= n.
Step 5: Repeat the following steps until the condition i <= n is false:
Increment i by 1: i = i + 1.
Step 6: End the loop when the condition i <= n is false.
Step 7: Print the value of sum.
Step 8: End the program.
While loop:
Step 1: Start the program.
Step 2: Initialize the product variable product = 1 to store the cumulative
product.
Step 3: Initialize the loop control variable i = 1.
Step 4: While the condition i <= n is true:
Multiply product by i: product = product * i.
Increment i by 1: i = i + 1.
Step 5: End the loop when the condition i <= n becomes false.
Step 6: Print the value of product.
Step 7: End the program.
Do….while
Step 1: Start the program.
Step 2: Initialize the total variable total = 100 and the loop control variable i
= 1.
Step 3: Execute the block of code once:
PANGASINAN STATE REGION’S PREMIER UNIVERSITY
5 LABORATORY BS MECHANICAL ENGINEERING
COMPUTER FUNDAMENTALS AND PROGRAMMING
REPORT
Subtract i from total: total = total - i.
Step 4: While the condition total > 0 is true:
Step 4.1: Increment i by 1: i = i + 1.
Step 4.2: Subtract i from total: total = total - i.
Step 5: End the loop when total <= 0.
Step 6: Print the final value of total.
Step 7: End the program.
6. Array
Step 1: Start the program.
Step 2: Input the size of the array n.
Step 3: Declare the array A[1..n] of size n.
Step 4: Initialize the sum variable sum = 0.
Step 5: Input values into the array A[1..n]:
For i = 1 to n, input A[i].
Step 6: Loop through the array to sum the elements:
For i = 1 to n:
Add A[i] to sum: sum = sum + A[i].
Step 7: Output the result: Print the value of sum.
Step 8: End the program.
PANGASINAN STATE REGION’S PREMIER UNIVERSITY