Doubt in the solution

hi, in the ith loop if we traverse from 1 to n-1 it gives the same output and also if I traverse from 0 to less than equal to n i get the same output can you please explain

Hi @mohammednomaan45 pls share ur code

#include
using namespace std;
void bubble_sort(int arr[],int n){

for(int i=0;i<=n;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[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}

bubble_sort(arr,n);

for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}

}

so outer loop should run at max n times. either start from 0 and end at n-1 or start at 1 and end at n… both means the same

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.