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 a simple food delivery service software system

Create a simple food delivery service software system that manages customer call-in the orders for combo meals via a first/in-first/out method.

  What is encapsulation

What is encapsulation

  Compute the time required to cut the grass

Write a program that takes the length and width of a rectangular yard and the length and width of a rectangular house situated in the yard.

  Question regading the mean value theorem

Consider the function f(x) = x^2 on the interval [0,1]. According to the Mean Value Theorem, there must be a number c in (0, 1/2 ) such that f ′(c) is equal to a particular value d. What is d?

  Creates an enumerated data type year

Implement a C++ program that creates an enumerated data type Year that consists of the twelve months from January to December. Read from input the number of visitors to Olympic Park for each month and then calculate the total number of visitors for a..

  Write a header for the function named subtract

Write a header for the function named subtract. Subtract returns nothing and has one double parameter named num.

  Problem related to calculating average in program

Here's the program i must do: 3 evaluators will evaluate 4 parameters ( just name them parameter1, parameter2 ...) the program must ask the evaluators to input those parameters but as letters (N=1,M=2,S=3,B=4,E=5) then I have to do the average for..

  You are the admissions office at abc medical university

You are the Admissions Office at ABC Medical University. You have a large number of applicants for a very few number of available openings at your school. As a result, you need to set some high admission standards. To be accepted, a student ..

  Braces for blocks of code

C-- should have braces for blocks of code, an if statement, while statement, and a double, int, and character. Each statement ends with a semi-colon and you must have a main routine

  Program that asks user to enter the size of the matrix

Write a program that asks user to enter the size of the matrix (rows and column) then, it asks the user to enter the elements of two matrices and finally it adds two matrix and displays the result in C language.

  Write application which ask user to input grades of students

Write C++ application which asks user to input grades for 5 student (3 grades each) save them in five double one dimensional arrays (one array for each student),

  Write a class player that contains attributes for the player

Write a class player that contains attributes for the players name,average and team.write three functions to input change and display these attributes. also write a constructor that ask for input to initialize all the attributes.

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