Click here to Skip to main content
15,888,000 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
hello. please write this algorithm (following picture link) (for example 1-start 2-declare sum,n,t,i 3-read n ....) many many thanks.

https://atechdaily.com/resources/images/posts/2021/1/506/flowchart-for-series-of-s-1-3-5-7.png[^]

What I have tried:

How do I write this algorithm or change flowchart to algorithm ?
Posted
Updated 26-Oct-21 8:10am
v2
Comments
PIEBALDconsult 26-Oct-21 12:39pm    
Sounds like homework.
And does the person who created the flowchart not know the symbol for a for loop?

1 solution

1. Input n.
2. Set i to 1.
3. If i is greater than or equal to 2 x n, go to step 9.

[for you to fill in]

9. Output sum and stop.

Step 9 could turn out to be numbered something else, like 8 or 10.

EDIT: What happens if the user enters 0 for n? The flowchart is flawed unless it assumes that sum is magically initialized.
 
Share this answer
 
v3
Comments
phil.o 26-Oct-21 15:12pm    
There are other flaws. For example, a for loop is taken for a conditional statement.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900