CSS 113 (PROBLEM SOLVING) ALGORITHM ASSIGNMENT

 

CSC 113

WRITE THE ALGORITM FOR FINDING THE FOLLOWING;

NOTE: biko (please) change the grammar/english/write-up a bit to avoid copied worked.

1. THE AREA OF A RECTANGLE

EXAMPLE 1

Inputs:

- length: the length of the rectangle

- width: the width of the rectangle

Output:

- perimeter: the perimeter of the rectangle

Step 1. Start

Step 2. Input the length of the rectangle

Step 3. Input the width of the rectangle

Step 4. Multiply the length by 2

Step 5. Multiply the width by 2

Step 6. Add the results of step 3 and step 4 together

Step 7. Assign the result to a variable called "perimeter"

Step 8. Display the value of the "perimeter" variable

Step 9. End

 

EXAMPLE 3

Input: length

Input: width

Output: perimeter

Step 1. Start

Step 2. Input the length of the rectangle

Step 3. Input the width of the rectangle

Step 4. Add length to width

Step 5. Multiply the result of step 3 by 2

Step 6. Add the results of step 3 and step 4 together

Step 7. Assign the result of step 6 to a variable called "perimeter"

Step 8. Display the value of the "perimeter" variable

Step 9. End

EXAMPLE 4

Input: length

Input: width

Output: perimeter

Step 1. Start

Step 2. L ← length

Step 3. W ← width

Step 4. P ← perimeter

Step 5. P ← 2 x (L + W)

Step 6. Print P

Step 7. End

 

EXAMPLE 5

Inputs:

- length: the length of the rectangle

- width: the width of the rectangle

Output:

- perimeter: the perimeter of the rectangle

Step 1. Start

Step 2. Read the value of length

Step 3. Read the value of width

Step 4. Compute the perimeter using the formula: perimeter = 2 * (length + width)

Step 5. Assign the value of perimeter to the variable called "perimeter"

Step 6. Display the value of perimeter

Step 7. End


2. FACTORIAL OF A GIVEN NUMBER "N"

IF YOU NEED AN EXPLANATION ON WHAT THE BELOW ALGORITHM MEANS CONTACT ME VIA WHATSAPP: 08161780381 WITH AIRTEL #100 OR ELSE COPY WHAT YOU SEE.

EXAMPLE 1

Input: N

Output: factorial

Step 1: Start

Step 2: Input a number N

Step 3:  Set a variable called "factorial" to 1

Step 4: If N is less than 0, display an error message and end the algorithm

Step 5: If N equals 0, set "factorial" to 1 and skip to step 8

Step 6: For i = 1 to N do steps 7 and 8

Step 7: Multiply "factorial" by i

Step 8: End loop

Step 9: Display the value of "factorial"

               Step 10: End


EXAMPLE 1

Input: N

Output: factorial

Step 1: Start

Step 2: Input a number N

Step 3:  Set a variable called "factorial" to 1

Step 4: If N is less than 0, display an error message and end the algorithm

Step 5: If N equals 0, set "factorial" to 1 and skip to step 8

Step 6: For i = 1 to N do steps 7 and 8

Step 7: Multiply "factorial" by i

Step 8: End loop

Step 9: Display the value of "factorial"

               Step 10: End

EXAMPLE 2

Input: N

Output: factorial

Step 1. Start

Step 2. Input the value of N

Step 3. Initialize a variable called "factorial" to 1

Step 4. Set up a loop that will run from 1 to N

Step 5. For each iteration of the loop, multiply "factorial" by the current loop index

Step 6. After the loop completes, the final value of "factorial" is the factorial of N

Step 7. Display the value of "factorial"

Step 8. End

EXAMPLE 3

Input: N

Output: factorial

Step 1. Start

Step 2. Input a number N

Step 3. Set a variable called "factorial" to 1

Step 4. If N is less than 0, display an error message and end the algorithm

Step 5. If N equals 0, set "factorial" to 1 and skip to step 8

Step 6. For i = 1 to N do steps 7 and 8

Step 7. Multiply "factorial" by i and assign the result to "factorial"

Step 8. End loop

Step 9. Display the value of "factorial"

Step 10. End

follow us

Share page pls

Comments

Popular posts from this blog