In: Computer Science
Unit 09 Drop Box Assignment
ONLY ONE FILE may be turned in for the assignment. If you make a
mistake and need to turn
in your work again, you may do so. I will only grade the latest
file you turn in. The older ones
will be ignored. For instruction on How To do assignments and
create the file see the "How To
Do Homework" document under the "Start Here" button.
The Assignment
Create a Visual Logic flow chart with four methods. Main method
will create an array of 5
elements, then it will call a read method, a sort method and a
print method passing the array
to each. The read method will prompt the user to enter 5 numbers
that will be stored in the
array. The sort method will sort the array in ascending order
(smallest to largest). The print
method will print out the array.
A sample run might look like this:
Please enter a number: 2
Please enter a number: 7
Please enter a number: 1
Please enter a number: 10
Please enter a number: 3
Your numbers are: 1, 2, 3, 7, 10
Visual Logic Flow Chart for the above four methods :-

Explanation :-
An array[5 ] is declared in main method of int type . In the main method the method read method is declared and defined and also called to take array elements as the input from the user . Using this array the sort method is called and the array elements are sorted in ascending order . This sorted array is used to call the print method that prints the sorted array on the output console .
The working code for the above question in language C is :-
#include <stdio.h>
int main()
{
int array[5];
void read()
{
for(int i = 0 ; i < 5 ; i++)
{
printf("Please enter a number : ");
scanf("%d",&array[i]);
}
}
read();
void sort()
{
for(int j = 0 ; j < 5 ; j++)
{
for(int k = j+1 ; k < 5 ; k++)
{
if(array[j] > array[k])
{
int t = array[j];
array[j] = array[k];
array[k] = t;
}
}
}
}
sort();
void print()
{
printf("The sorted array is : ");
for(int l = 0 ; l < 5 ; l++)
{
printf("%d " , array[l]);
}
}
print();
return 0;
}
Screenshot of the result :-
