Posttest (Finals)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

Name: Marc Jhon A.

Benzal Course: ES 132


Program and Year: BSCE 2A Instructor: Ma’am Anne Say Morite

LEARNING MODULE NO. 6 – POSTTEST

1. Develop a program in C++ to find the first 10 natural numbers.


Sample output:
The natural numbers are:
1 2 3 4 5 6 7 8 9 10
LEARNING MODULE NO. 6 – POSTTEST

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

3. Write a program to display n terms of natural number and their sum.


Sample Output:
Input a number of terms: 7
The natural numbers up to 7th terms are:
1234567
The sum of the natural numbers is: 28
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

5. Develop a program in C++ to check whether a number is prime or not.


Sample Output:
Input a number to check prime or not: 13
The entered number is a prime number.
LEARNING MODULE NO. 6 – POSTTEST

6. Develop a program in C++ to find a prime number within a range.


Input number for starting range: 1
Input number for ending range: 100
The prime numbers between 1 and 100 are:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
The total number of prime numbers between 1 to 100 is: 25
LEARNING MODULE NO. 6 – POSTTEST

7. Develop a program in C++ to find the factorial of a number.


Sample output:
Input a number to find the factorial: 5
The factorial of the given number is: 120
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

LEARNING MODULE NO. 7 – POSTTEST

Instructions: For each question, encircle the letter of the correct best answer.

1. Write a program to sort a numeric array and a string array.


2. Write a program to sum values of an array.

3. Write a program to print the following grid.


4. Write a program to calculate the average value of array elements.

5. Write a program to test if an array contains a specific value.


6. Write a program to find the index of an array element.

7. Write a program to remove a specific element from an array.


8. Write a program to insert an element (specific position) into an array.
9. Write a program to find the maximum and minimum value of an array.
10. Write a program to multiply two matrices using multi-dimensional arrays.
11. Develop a program to compute the transpose of the matrix and displays it on the screen.
12. Develop a program in C++ to find the first 10 natural numbers.

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

LEARNING MODULE NO. 8 – POSTTEST

Instructions: For each question, encircle the letter of the correct best answer.

1. Write a function-oriented program to find the maximum of three numbers.


2. Write a function-oriented program Python function to sum all the numbers in a list.

3. Write a function-oriented program to multiply all the numbers in a list.


4. Write a function-oriented program to reverse a string.
5. Write a function-oriented program to calculate the factorial of a number (a non-
negative integer). The function accepts the number as an argument.
6. Write a function-oriented program to check whether a number falls within a given
range.
7. Write a Python function that accepts a string and counts the number of upper- and
lower-case letters.
8. Write a function-oriented program in C++ to find the square of any number using
the function.
9. Write a function-oriented program in C++ to swap two numbers using a function.
10. Write a function-oriented program in C++ to check if a given number is even or
odd using the function.
11. Write a function-oriented program in C++ to find the sum of the series 1! /1+2!
/2+3! /3+4! /4+5! /5 using the function.
12. Write a function-oriented program in C++ to convert a decimal number to a binary
number using the function.
13. Write a function-oriented program in C++ to check whether a number is a prime
number or not using the function.
14. Write a function-oriented program in C to check Armstrong and Perfect numbers
using the function.
15. Write a program in C to print all perfect numbers in a given range using the
function.

You might also like