Develop an algorithm to arrange a list of 10 integer positive
numbers in order
from the lowest to the highest. It has to be with Flowgorithm.
Here is the completed code for this problem. Comments are included, go through it, learn how things work and let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks
Note: I have attached the required program in Flowgorithm in picture format as well as .fprg file format. If the image looks blurry or if you need to see it better, please save the attached program.fprg file in your system (make sure the extension is .fprg) and open that file in flowgorithm.
FLOWGORITHM SCREENSHOT
OUTPUT
PROGRAM.fprg FILE
<?xml version="1.0"?>
<flowgorithm fileversion="2.11">
<attributes>
<attribute name="name" value=""/>
<attribute name="authors" value="Enigma"/>
<attribute name="about" value=""/>
<attribute name="saved" value="2019-09-04 08:28:08 AM"/>
<attribute name="created" value="RW5pZ21hO1RJVEFOSVVNOzIwMTktMDktMDQ7MDg6MTE6MjUgQU07MjQ4Mw=="/>
<attribute name="edited" value="RW5pZ21hO1RJVEFOSVVNOzIwMTktMDktMDQ7MDg6MTU6MTggQU07MTtFbmlnbWE7VElUQU5JVU07MjAxOS0wOS0wNDswODoxMzo1NCBBTTtGb3IuZnByZzs1OTc0"/>
<attribute name="edited" value="RW5pZ21hO1RJVEFOSVVNOzIwMTktMDktMDQ7MDg6Mjg6MDggQU07MTsyNjAw"/>
</attributes>
<function name="Main" type="None" variable="">
<parameters/>
<body>
<declare name="size, i, j, temp" type="Integer" array="False" size=""/>
<assign variable="size" expression="10"/>
<declare name="numbers" type="Integer" array="True" size="size"/>
<comment text="filling the array with some random numbers between 0 and 99"/>
<for variable="i" start="0" end="size-1" direction="inc" step="1">
<assign variable="numbers[i]" expression="Random(100)"/>
</for>
<comment text="displaying numbers before sorting"/>
<output expression=""Numbers before sorting"" newline="True"/>
<for variable="i" start="0" end="size-1" direction="inc" step="1">
<output expression="" "&numbers[i]" newline="False"/>
</for>
<output expression="""" newline="True"/>
<comment text="now we can sort the numbers in ascending order, using bubble sort algorithm"/>
<for variable="i" start="0" end="size-1" direction="inc" step="1">
<for variable="j" start="0" end="size-2" direction="inc" step="1">
<comment text="comparing numbers at indices j and j+1"/>
<if expression="numbers[j]>numbers[j+1]">
<then>
<comment text="swapping elements at indices j and j+1"/>
<assign variable="temp" expression="numbers[j]"/>
<assign variable="numbers[j]" expression="numbers[j+1]"/>
<assign variable="numbers[j+1]" expression="temp"/>
</then>
<else/>
</if>
</for>
</for>
<comment text="now displaying numbers in sorted order"/>
<output expression=""Numbers arranged from lowest to highest"" newline="True"/>
<for variable="i" start="0" end="size-1" direction="inc" step="1">
<output expression="" "&numbers[i]" newline="False"/>
</for>
</body>
</function>
</flowgorithm>
Get Answers For Free
Most questions answered within 1 hours.