0

Can you please help me?

The code c++ does not give correct results for the ascending arrangement of an array (one dimension), what is fail here? int arr[4] , val=0; cout<<"Enter Value Array:\n"<<"--------------------\n"; for(int i=0 ; i<4 ; i++) cin>>arr[i]; for(int i=0 ; i<4 ; i++){ for(int j=1 ; j<4; j++) if (arr[j]<arr[i]){ val=arr[j]; arr[j]=arr[i]; arr[i]=val; } } for(int i=0 ; i<4 ; i++) cout<<arr[i]<<"\t";

24th Apr 2020, 10:51 PM
Mustafa Ch
Mustafa Ch - avatar
3 Respostas
0
for(int i=0 ; i<4 ; i++){ for(int j=0 ; j<4; j++) // initialise 'j' with 0. if (arr[j]<arr[i]){ val=arr[j]; arr[j]=arr[i]; arr[i]=val; } }
24th Apr 2020, 11:13 PM
rodwynnejones
rodwynnejones - avatar
0
thank's
24th Apr 2020, 11:35 PM
Mustafa Ch
Mustafa Ch - avatar
0
You can also initialise the 'i' to 1, together with the 'j' to 0;
24th Apr 2020, 11:49 PM
rodwynnejones
rodwynnejones - avatar