Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
623 B
2
Indexable
Never
#include<iostream>
using namespace std;
void display(int*array,int size)
{
	for(int i=0;i<size;i++)
	cout <<array[i]<<"";
	cout<<endl;
}
void bubblesort(int*array,int size)
{
	for(int i=0;i<size;i++)
	for(int j=0;j<size-i-1;j++)
	if(array[j]>array[j+1])
	{
		int temp;
		temp=array[j]=array[j+1];
		array[j+1]=temp;
	}
}
int main()
{
	int n;
	cout<<"Enter the number of elements:";
	cin>>n;
	int arr[n];
	cout<<"Enter elements:"<<endl;
	for(int i=0;i<n;i++)
	cin>>arr[i];
	cout<<"Array before sorting:";
	display(arr,n);
	bubblesort (arr,n);
	cout<<"Array afte sorting:";
	display(arr,n);
}