
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A c++ program that implements the bubble sort algorithm to arrange an array of integers in ascending order. The program uses two nested for loops to compare adjacent elements and swap them if they are in the wrong order. The sorted array is then printed out using the cout statement. This document can be useful for students and lifelong learners who are studying computer science, data structures, or algorithms, as it provides a practical example of how to implement a common sorting algorithm in c++.
Typology: Exercises
1 / 1
This page cannot be seen from the preview
Don't miss anything!

#include<iostream.h> #include<conio.h> void main (void) { int a[10]={3,4,51,8,5,45,7,0,9,11}; int i,j,b; clrscr(); for (i=0;i<=10;i++) for (j=i+1;j<10;j++) { if (a[i]>=a[j]) { b=a[i]; a[i]=a[j]; a[j]=b; } } for (i=0;i<10;i++) { cout<<" "<<a[i]; } getch(); }