+ 1
Why this code is taking garbage values ?
I am running this code, for 7 values and it is fine (I changed it to take 7 values at that time). But when I am trying it for 10 values, it is taking garbage values. Plz help me out 🙏 #include <iostream> using namespace std; int main() { int i,j,temp; int arr[10]; cout<<"Enter the ten numbers that are to be sorted : "<<endl; for(i=0;i<10;i++) { cin>>arr[i]; } for(i=0;i<10;i++) { for(j=0;j<10-i;j++) { if(arr[j]<arr[j+1]) { temp = arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; } } } cout<<"The sorted numbers are : "<<endl; for(i=0;i<10;i++) { cout<<arr[i]<<" "; } return 0; } Plz help 🙏
5 Answers
+ 3
Put your code in code playground and add link (+ button) in the question description. This way, we can run it and see the problem.
+ 2
Emerson Prado
Here it is
This is the actual code what I've written without any corrections
https://code.sololearn.com/c83wuR1FjbKz/?ref=app
+ 1
Martin Taylor Thanks a lot for the help 🙏🙏
+ 1
Krishnendu Dey Good, now I see it. I was to write about the invalid array index, but Martin Taylor already did it and more. Stick with him.
+ 1
Ok Thanks Emerson Prado