You are on page 1of 7

MidTerm Laboratory No.

1: Loop Structures
Activity 1.
1. Write a program that prints all even numbers from 1 to 50 inclusive using the for loop,
while loop, and do…while loop. The class name is EvenNum. (20PTS)
Expected output:

Your Source Code:

Your Output:
Activity 1.2. Write a program that sums the integers from 1 to 50 using any looping
statement. The class name is Sum50. (20PTS)

Expected output:

Your Source Code:

Your Output:
Activity 1.3. Write a program that prints every integer value from 1 to 20 along with its
squared value using the following looping structures (for, while, and do-while loop). The
class name is TableOfSquares. (30PTS)
Expected output:

Your Source code:


Your Output:
Activity 1.4. Write a fragment of code that will compute the sum of the first n positive odd
integers. For example, if n is 5, you should compute 1 + 3 + 5 + 7 + 9. Thus, the result is
25. Class name : SumOfNOdd. (30PTS)
Expected Output:

Your Sourcecode:

Your Output:
Activity 1.5. Write a for statement to compute the sum of an N as an entered integer 1 +
2² + 3² + 4² + 5² + ... + N². (50PTS)
Expected Output:

Your source code:

Your Output:

You might also like