Bubble sort creating problem


i can’t understand why op shows 0 in begining even if its not in ip
Please sort it fast i want to complete challange

@rastogi.g1998


Your modified code
Kindly close the doubt

https://online.codingblocks.com/app/player/39329/content/76833/4812/code-challenge

please check this problem my 3 testcase failed do we have to print index or elements whos sum is equal to target

although it passed test case

hello @rastogi.g1998
a)
In ur bubble sort
image
use < in place of <=

b)
image
remove this else part becuase j is already decrementing by for loop.

ur updated code->

#include using namespace std; void bubblesort(int arr[],int n){ for(int i=0;i<=n-1;i++){ for(int j=0;j<=n-i-1;j++){ if(arr[j]>arr[j+1]){ swap(arr[j],arr[j+1]); } } } } int main() { int n; cin>>n; int arr[1000]; for(int i=0;i<n;i++){ cin>>arr[i]; } bubblesort(arr,n); int target; cin>>target; for(int i=0;i<n;i++){ for(int j=n-1;j>=0;j–){ int sum=arr[i]+arr[j]; if(sum==target){ if(arr[i]<arr[j]){ cout<<arr[i]<<" and “<<arr[j]<<endl; } else{ cout<<arr[j]<<” and "<<arr[i]<<endl; } } else{ j–; } } } }