Posttest (Finals)
Posttest (Finals)
Posttest (Finals)
2. Develop a program in C++ to find the sum of the first 10 natural numbers.
Sample Output:
Find the first 10 natural numbers:
---------------------------------------
The natural numbers are: 1 2 3 4 5 6 7 8 9 10
The sum of first 10 natural numbers: 55
LEARNING MODULE NO. 6 – POSTTEST
4. Develop a program in C++ to find the perfect numbers between 1 and 500.
The perfect numbers between 1 to 500 are:
6
28
496
LEARNING MODULE NO. 6 – POSTTEST
8. Develop a program in C++ to find the last prime number that occurs before the entered
number.
Sample Output:
Input a number to find the last prime number occurs before the number: 50
47 is the last prime number before 50
LEARNING MODULE NO. 6 – POSTTEST
9. Develop a program in C++ to find the Greatest Common Divisor (GCD) of two numbers.
Sample Output:
Input the first number: 25
Input the second number: 15
The Greatest Common Divisor is: 5
LEARNING MODULE NO. 6 – POSTTEST
10. Develop a program in C++ to find the sum of the digits of a given number.
Sample Output:
Input a number: 1234
The sum of digits of 1234 is: 10
LEARNING MODULE NO. 6 – POSTTEST
11. Develop a C++ program that asks the user to enter positive integers in order to process
count, maximum, minimum, and average or terminate the process with -1.
Sample Output:
Your input is for termination. Here is the result below:
Number of positive integers is: 4
The maximum value is: 9
The minimum value is: 3
The average is 6.00
LEARNING MODULE NO. 6 – POSTTEST
12. Develop a C++ program to list non-prime numbers from 1 to an upper bound.
Sample Output:
Input the upper limit: 25
The non-prime numbers are: 4 6 8 9 10 12 14 15 16 18 20 21 22 24 25
LEARNING MODULE NO. 6 – POSTTEST
13. Develop a program in C++ to print a square pattern with the # character.
Sample Output:
Print a pattern like square with # character:
--------------------------------------------------
Input the number of characters for a side: 4
####
####
####
####
LEARNING MODULE NO. 6 – POSTTEST
14. Develop a program in C++ to display the multiplication table vertically from 1 to n.
Sample Output:
Input the number up to: 5
Multiplication table from 1 to 5
1x1=1 2x1=2 3x1=3 4x1=4 5x1=5
1x2=2 2x2=4 3x2=6 4x2=8 5x2=10
1x3=3 2x3=6 3x3=9 4x3=12 5x3=15
1x4=4 2x4=8 3x4=12 4x4=16 5x4=20
1x5=5 2x5=10 3x5=15 4x5=20 5x5=25
1x6=6 2x6=12 3x6=18 4x6=24 5x6=30
1x7=7 2x7=14 3x7=21 4x7=28 5x7=35
1x8=8 2x8=16 3x8=24 4x8=32 5x8=40
1x9=9 2x9=18 3x9=27 4x9=36 5x9=45
1x10=10 2x10=20 3x10=30 4x10=40 5x10=50
LEARNING MODULE NO. 6 – POSTTEST
15. Develop a C++ program that displays the sum of n odd natural numbers.
Sample Output:
Input number of terms: 5
The odd numbers are: 1 3 5 7 9
The Sum of odd Natural Numbers up to 5 terms: 25
Name: Marc Jhon A. Benzal Course: ES 132
Program and Year: BSCE 2A Instructor: Ma’am Anne Say Morite
Instructions: For each question, encircle the letter of the correct best answer.
13. Develop a program in C++ to find the sum of the first 10 natural numbers. Note: Use arrays
in solving this problem.
14. Develop a program in C++ to print a square pattern with the # character.
15. Develop a program in C++ to display the multiplication table vertically from 1 to n.
Name: Marc Jhon A. Benzal Course: ES 132
Program and Year: BSCE 2A Instructor: Ma’am Anne Say Morite
Instructions: For each question, encircle the letter of the correct best answer.