Create a c program that sorts a sequence of positive numbers

Assignment Help C/C++ Programming
Reference no: EM131309829

C-Programming

Create a C program that sorts a sequence of positive numbers using the bubble sort algorithm in an increasing or decreasing order based on the user's choice. The pseudo code for the bubble sort algorithm is shown below.

function bubblesort( A : list of numbers )
for each i=length(A)-1 to 0
for each j=1 to i
if A[j-1] > A[j]
swap( A[j-1], A[j] )
end if
end for
end for
end function

The program prompts the user for the sequence of numbers to be sorted followed by the sort order. You can assume a maximum of 100 numbers will be entered. You can also assume the user will enter 0 to mark the end of the input.

Program Specification:

1) Have three functions besides main:

a. one that accepts the sequence of numbers

b. one that sorts the sequence of numbers; this function should take three parameters: the sequence of numbers as an array, size of the sequence, and the sorting order

c. a swap function to be called from the sorting function

2) The main function prints the sorted sequence of numbers

3) The program ignores inputs that are negative numbers.

4) You can use the strcmp c string comparison function in this program; strcmp takes two strings as input and returns 0 if the two strings are equal or a non-zero value if the input strings are not equal.

Sample Run of the Program:

C:\> sort <enter>
Enter sort order: up
Enter a sequence of numbers: 10 2 1 3 40 20 0
1 2 3 10 20 40

Reference no: EM131309829

Questions Cloud

How many members does class bagtype have : CIS242 Assignment- How many members does class bagType have? How many private members does class bagType have? How many constructors does class bagType have? How many constant functions does class bagType have?
How abstraction and encapsulation enable evolutionary change : Begin with a simple enhancement: charging a fee for every deposit and withdrawal. Supply a mechanism for setting the fee and modify the deposit and withdraw methods so that the fee is levied. Test your resulting class and check that the fee is com..
Value of covariance between stock and bond funds : Consider the following table: Stock Fund Bond Fund Scenario Probability Rate of Return Rate of Return Severe recession 0.20 −38% −12% Mild recession 0.20 −26% 7% Normal growth 0.35 8% 3% Boom 0.25 46% 7% a. Calculate the values of mean return and var..
Compare and contrast needs based theories of motivation : Compare and contrast needs-based theories of motivation.- Which offers the most value to healthcare managers?
Create a c program that sorts a sequence of positive numbers : Create a C program that sorts a sequence of positive numbers using the bubble sort algorithm in an increasing or decreasing order based on the user's choice. The pseudo code for the bubble sort algorithm is shown below.
Strategic management and competitiveness : What factors make up this process?- How important is it to change, and what criteria determine the changes in a strategic management plan?
Implement a votingmachine class used for simple election : Extra credit if your program gives the nod to your favored party if the votes are tallied after 8 P.M. on the first Tuesday in November, but acts normally on all other dates.
Development show signs of a weak sense of mission : Using the Ashridge Sense of Mission Model analyse the case evidence to critically examine the argument that Twitter's current growth and development show signs of a weak sense of mission.
What is the amount of four equal payments : A debt of $1,000 is incurred at   t = 0. What is the amount of four equal payments at   t = 1, 2, 3, and 4 that will repay the debt if money is worth 10 percent compounded per period?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd