I need a simple bubble sort program that takes a file in the same folder as the
ID: 3683211 • Letter: I
Question
I need a simple bubble sort program that takes a file in the same folder as the source code named "datain.txt" (that is an arbatrary list of numbers) and outputs the original list to the screen, outputs the sorted list to the screen and also to an external file (named dataout.txt).The numbers should be sorted using a very simple buble sort.
STEPS:
Import external file as an array into program.
Output imported array to screen.
Pass imported array to UDF and sort using “Bubble Sort”.
Output sorted array to screen and to output file called “DataOut.txt”.
Try to comment liberally.
Explanation / Answer
int main()
{
for (i = 0; i < n; i++)
{
for (i = 0; i < n; i++)
{
for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (a[i] > a[j])
{
for (i = 0; i < n; i++)
{
#include<stdio.h>int main()
{
int a[50], n, i, j, temp = 0; printf("Enter how many numbers you want: "); scanf("%d", &n); printf("Enter the %d elements: ", n);for (i = 0; i < n; i++)
{
scanf("%d", &a[i]); } printf(" The given array is: ");for (i = 0; i < n; i++)
{
printf(" %d", a[i]); }for (i = 0; i < n; i++)
{
for (j = i + 1; j < n; j++)
{
if (a[i] > a[j])
{
temp = a[i]; a[i] = a[j]; a[j] = temp; } } } printf(" The sorted array using Buble sort is: ");for (i = 0; i < n; i++)
{
printf(" %d", a[i]); } return 0; }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.