0% found this document useful (0 votes)
22 views16 pages

Post Test6 Benzal MJ

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views16 pages

Post Test6 Benzal MJ

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

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

You might also like