Answer to Question #297071 in Algorithms for EDEN

Question #297071

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-12T12:56:51-0500


for loops


Start
Declare Integer firstNum
Declare Integer secondNum
Declare Integer i
Declare Integer sumEvenNum
Declare Integer sumSqOddNum


Set sumEvenNum = 0
Set sumSqOddNum = 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 sumEvenNum = sumEvenNum + i
    End If
End For
Display "The sum of all even numbers between firstNum and secondNum: ", sumEvenNum
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 sumSqOddNum = sumSqOddNum + i * i
    End If
End For
Display "The sum of the square of the odd numbers between firstNum and secondNum: ", sumSqOddNum
Stop


 do. . .while loops.
Start
Declare Integer firstNum
Declare Integer secondNum
Declare Integer i
Declare Integer sumEvenNum
Declare Integer sumSqOddNum


Set sumEvenNum = 0
Set sumSqOddNum = 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 sumEvenNum = sumEvenNum + i
    End If
    Set i = i + 1
While i <= secondNum
Display "The sum of all even numbers between firstNum and secondNum: ", sumEvenNum
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 sumSqOddNum = sumSqOddNum + 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: ", sumSqOddNum
Stop

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