0% found this document useful (0 votes)
5 views1 page

C++ Program for Sorting Integers

The document contains C++ code to sort a vector of integers in ascending order using bubble sort. It takes user input for the number of elements and their values, stores them in a vector, performs bubble sort on the vector, and outputs the sorted values.

Uploaded by

Alagar raja
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

C++ Program for Sorting Integers

The document contains C++ code to sort a vector of integers in ascending order using bubble sort. It takes user input for the number of elements and their values, stores them in a vector, performs bubble sort on the vector, and outputs the sorted values.

Uploaded by

Alagar raja
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

#include <iostream>

#include <vector>
using namespace std;
int main() {
vector<int> a;
int value,n,find;
bool b=true;
cout<<"Enter n : ";
cin>>n;
cout<<"Enter "<<n<<" elements :"<<endl;
for(int i=0;i<n;i++)
{
cin>>value;
a.push_back(value);
}
for(int i=0;i<n;i++)
{
for(int j=i+1;j<n;j++)
{
if(a[i]<a[j])
{
a[i]=a[i]+a[j];
a[j]=a[i]-a[j];
a[i]=a[i]-a[j];
}
}
}
for(int i:a)
{
cout<<i<<" ";
}
return 0;
}

You might also like