60 465
Assignments Done
98,1%
Successfully Done
In April 2018

Answer to Question #3276 in C++ for Jakir

Question #3276
I want to get some examples of Bubble short program of C++
Expert's answer
#include //bubble sort
void bubbleSort(int mas[], const int n){
for(int i = 0; i < n; i++){
for(int o = 0; o < n-1-i; o++){
if(mas[o] > mas[o+1]){
//swap elements
int x = mas[o];
mas[o] = mas[o+1];
mas[o+1] = x;
}
}
}
}

int main(){
int n;
printf("Input quantity: ");
scanf("%d",&n);
if(n<=0){
return 0;
}
int* mas = new int[n];
//Enter numbers
printf("Enter numbers
");
for(int i = 0; i < n; i++){
scanf("%d",&mas[i]);
}
//sort numbers
bubbleSort(mas,n);
//print sorted array
printf("Result:
");
for(int i = 0; i < n; i++){
printf("%d ",mas[i]);
}

return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions