Answer to Question #296885 in Algorithms for Fedii

Question #296885

a. Write algorithm using pseudocode and flowchart that uses while loops to perform the 

following steps:

i. Prompt the user to input two integers: firstNum and secondNum note that firstNum 

must be less than secondNum.

ii. Output all odd numbers between firstNum and secondNum.

iii. Output the sum of all even numbers between firstNum and secondNum.

iv. Output the numbers and their squares between firstNum and secondNum.

v. Output the sum of the square of the odd numbers between firstNum and secondNum.

b. Redo Exercise (a) using for loops.

c. Redo Exercise (a) using do. . .while loops.


1
Expert's answer
2022-02-12T08:06:47-0500
using for loops.

Declare Integer firstNum
Declare Integer secondNum
Declare Integer i
Declare Integer sumAllEvenNumbers
Declare Integer sumSquareOddNumbers


Set sumAllEvenNumbers = 0
Set sumSquareOddNumbers = 0
Display "Enter firstNum: "
Input firstNum
Set secondNum = firstNum
While firstNum >= secondNum
    Display "Enter secondNum: "
    Input secondNum
End While
Display "All odd numbers between firstNum and secondNum:"
For i = firstNum To secondNum
    If i MOD 2 != 0 Then
        Display i
    Else
        Set sumAllEvenNumbers = sumAllEvenNumbers + i
    End If
End For
Display "The sum of all even numbers between firstNum and secondNum: ", sumAllEvenNumbers
Display "The numbers and their squares between firstNum and secondNum:"
For i = firstNum To secondNum
    Display i, "^2 = ", i * i
    If i MOD 2 != 2 Then
        Set sumSquareOddNumbers = sumSquareOddNumbers + i * i
    End If
End For
Display "The sum of the square of the odd numbers between firstNum and secondNum: ", sumSquareOddNumbers



do. . .while loops.

Declare Integer firstNum
Declare Integer secondNum
Declare Integer i
Declare Integer sumAllEvenNumbers
Declare Integer sumSquareOddNumbers


Set sumAllEvenNumbers = 0
Set sumSquareOddNumbers = 0
Display "Enter firstNum: "
Input firstNum
Set secondNum = firstNum
Do
    Display "Enter secondNum: "
    Input secondNum
While firstNum >= secondNum
Display "All odd numbers between firstNum and secondNum:"
Set i = firstNum
Do
    If i MOD 2 != 0 Then
        Display i
    Else
        Set sumAllEvenNumbers = sumAllEvenNumbers + i
    End If
    Set i = i + 1
While i <= secondNum
Display "The sum of all even numbers between firstNum and secondNum: ", sumAllEvenNumbers
Display "The numbers and their squares between firstNum and secondNum:"
Set i = firstNum
Do
    Display i, "^2 = ", i * i
    If i MOD 2 != 2 Then
        Set sumSquareOddNumbers = sumSquareOddNumbers + i * i
    End If
    Set i = i + 1
While i <= secondNum
Display "The sum of the square of the odd numbers between firstNum and secondNum: ", sumSquareOddNumbers





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS