0
In this sorting of array program why i am getting wrong output.
#include<iostream> using namespace std; //sorting of array //ascending int main() { int arr[5],i,a,j; cout<<"enter array elements \n"; for(i=0;i<=5;i++){ cin>>arr[i]; } for(j=0;j<=5;j++){ for(i=0;i<=(5-j);i++){ if(arr[i]>arr[i+1]){ a=arr[i]; arr[i]=arr[i+1]; arr[i+1]=a; } } } for(i=0;i<5;i++){ cout<<arr[i]; } return 0; }
3 Respostas
0
Add a space (or a line break) in between the array elements when printing the sorted array out, you'll see that it works.
0
It's working in sololearn but not on other compiler