Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Bubble Sort Program Project 2 Bubble Sort Due: 10th October 2017 Overview In thi

ID: 3590760 • Letter: B

Question

Bubble Sort Program

Project 2 Bubble Sort Due: 10th October 2017 Overview In this project you ll explore a basic algorithm for sorting. This will give you additional practice wit h input and output and conditional execution as l as providing an opportunity to try for-loops for the first time. Additionally, you will get more practice using Makefiles and the compiler and potentially even the debugger Submission Instr uctions This and aothr assignms be submitted through BBLearn Look for the submission link in the same place you found this assignment Submit all your .c and .h files along with your Makefile, but do not zip them! Note that your program may be evaluated by a program I compose for just this purpose. As such, when the instructions indicate that something should be printed in a certain way, failing to do so may cause my evaluator to reject your program! Technical Description and Instructions Your program needs to be able to do only a few simple tasks: 1. Display a welcome message (terminated by two blank lines, see Welcome Message for details). 2. Take in some integer numbers from the user (up to 20) (see Reading In Numbers for details). 3. Sort the numbers given (see Bubble Sort for details). 4. Print the numbers in sorted order (see Program Output for details) For this project, you don't need to worry about the kind of edge case handling that we did for the previous project. You may assume that your user will only give you good inputs with the exception of giving a number less than two for how many numbers they intend to sort as noted in Reading In Numbers Additionallv, be sure your makefile produces an executable called "bubble sort" so that my test script can run it Welcome Message Your welcome message may be whatever text you want to display except that it cannot contain two blank lines ( ') in a row as ths is how my grading program will determine that your welcome message is finished. By dint of the same fact, your welcome must end with two blank line:s

Explanation / Answer

#include<stdio.h>

int main(){

int n,i,x,y,temp=0; // Assuming n as input array size, x as completed_passes, y as current_index, temp as temp in pseudo code.

printf("Welcome User ");

printf("Please enter how many numbers you want to sort(up to 20): ");

scanf(" %d",&n); // Space before %d skips both given in above printf.

int data[n]; // Initializing a data array of size n

if(n<=2){ // Checking if n is greater than 2

printf("Since you have fewer than two numbers, they are already sorted! ");

}

else{

for(i=0;i<n;i++){

printf("Please enter the next number: ");

scanf(" %d",&data[i]); // Saving input array elements into data array

}

// Bubble sort algorithm

for(x=0;x<n;x++){

for(y=0;y<n-1-x;y++){

if(data[y]>data[y+1]){

temp = data[y];

data[y] = data[y+1];

data[y+1] = temp;

}

}

}

printf("Here are the results: ");

for(i=0;i<n;i++){

printf("%d ",data[i]);

}

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote