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; }

19th Jul 2022, 3:16 PM
SHĆȘBHÃM
SHĆȘBHÃM - avatar
3 Answers
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.
19th Jul 2022, 4:22 PM
Ipang
0
It's working in sololearn but not on other compiler
21st Jul 2022, 1:13 PM
SHĆȘBHÃM
SHĆȘBHÃM - avatar