This code is going infinite ...why?

#include
using namespace std;

int main(){

int arr[5]={3,2,-1,4,5};
for(int i=0;i<5;i++){
if(i!=0){

for(int j=i;j!=i-1;j++){
	if(j==5-1)j=0;

	for(int k=i;k<=j;k++){
		cout<<arr[k]<<" ";
	}cout<<endl;
 }

}
if(i==0){
for(int j=i;j<5;j++){

	for(int k=i;k<=j;k++){
		cout<<arr[k]<<" ";
	}cout<<endl;
 }

}
}

return 0;
}
//please explain me the output of this program also

Hi kartik
the loop for(int j=i;j!=i-1;j++) cause infinite loop.
I don’t understand why are you trying to print array elements. You have to print the max circular subarray sum.
Please read question carefully and then solve.

Hope it helps :slight_smile: