Hi!
I am trying to sort an array with Bubble shorting technique. it works fine until last value. when last value is to be sorted it converts last value in to 0 and sort it. any way to solve it.
Thanks
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int arr[10],i,j,temp;
for(i=0;i<=4;i++)
{
cout<<"Enter a number:";
cin>>arr[i];
}
cout<<"Orignal array is"<<endl;
for(i=0;i<=4;i++)
{
cout<<arr[i]<<"\t";
}
for(i=0;i<=4;i++)
{
for(j=0;j<=4;j++)
{
if(arr[j]>arr[j+1])
{
temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;
}
}
}
cout<<endl<<"Sorted array is"<<endl;
for(i=0;i<=4;i++)
{
cout<<arr[i]<<"\t";
}
getch();
return 0;
}