You are on page 1of 8

PATEROS CATHOLIC SCHOOL

Senior High School Department


F. Imson St., San Pedro, Pateros, Metro Manila SY
2020-2021
PROGRAMMING
ACTIVITY TASK SHEET No. 7

Learning Competencies:
1.1. Creating variables
1.2. Identifying constants in programming
1.3. Writing code using the correct syntax in programming
1.4. Using conditions in running programs
1.5. Using for loop in your program

PROGRAMMING EXERCISE

Situation: Your Grade 4 brother is having difficulty in his math subject in


terms of computing the factorial, square and cube of a number. You decided to help your brother to automate
this problem. Since you are excellent in Mathematics and a good programmer, you will make a simple program
to resolve this.

Task: Create an if else statement which requires the user to enter


character that determines that it is a FACTORIAL, CUBE OR SQUARE. Whenever the user enters ‘F’ = factorial,
‘C’ = cube and ‘S’ = square.

Use a while loop that will compute all the factorial, square or cube of the
value entered by the user.

EXAMPLE: User entered S and 7.

The expected output by the program is:

SQUARE OF 1 IS 1
SQUARE OF 2 IS 4
SQUARE OF 3 IS 9
SQUARE OF 4 IS 16
SQUARE OF 5 IS 25
SQUARE OF 6 IS 36
SQUARE OF 7 IS 49
EXAMPLE: User entered F and 11.

The expected output by the program is:

FACTORIAL OF 11 IS 39916800

EXAMPLE: User entered C and 5.

The expected output by the program is:

CUBE OF 1 IS 1
CUBE OF 2 IS 8
CUBE OF 3 IS 27
CUBE OF 4 IS 64
CUBE OF 5 IS 125
1. ALGORITHM

1.1. Create an algorithm that produces the output above.

AGORITHM

1. Declare Variables for the input number, square, cube, the value of factorial (1)
and n (0).

2. Input: number and operation.

3. Output: square, cube, factorial and the number.

4. Start if else statement.

5. If the input number is == ‘S’, then start loop.

Input: formula for square (n*n).

Output: square of the number.

6. If false, proceed to next condition.

7. If the input number is == ‘C’, then start loop.

Input: formula for cube (n*n)

Output: cube of the number.

8. If false, proceed to next condition.

9. If the input number is == ‘F’, then start loop.

Input: formula for factorial (f*n).

Output: factorial of the number.

10. If false, input else.

11. Output: INVALID INPUT.


2. FLOWCHARTING
2.1. Create a flowchart that produces the output above using if else and while loop.

FLOWCHART TITLE – FINDING THE SQUARE, CUBE AND FACTORIAL OF A NUMBER


3. PROGRAMMING USING JDOODLE

3.1. Proceed to this free website: https://www.jdoodle.com/online-compiler-c++/


3.2. Using the compiler, create an if else statement which requires the user to enter character that
determines that it is a FACTORIAL, CUBE OR SQUARE. Whenever the user enters ‘F’ = factorial, ‘C’ = cube
and ‘S’ = square.

Use a while loop that will compute all the factorial, square or cube of the
value entered by the user.

3.3. Write the correct program and the expected output above.
PROGRAM

EXPECTED OUTPUT

You might also like