Where I m doing Mistake can anyone identify plz | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Where I m doing Mistake can anyone identify plz

https://code.sololearn.com/c78YSQDOTKeL/?ref=app

14th Oct 2021, 2:48 PM
PRIYANSHU GOYAL
PRIYANSHU GOYAL - avatar
2 Answers
+ 1
One issue is that you try to initialize in "arr" with "n" before "n" is defined. Also look at line 33: here we have "a" instead of "arr"
14th Oct 2021, 2:55 PM
Lisa
Lisa - avatar
0
//corrected code , see comments.. //for better understanding, add more description about problem #include <iostream> using namespace std; int main() { //int arr[n]; n is not declared yet. move to after n assignment int i ,j ,n , temp; cout<<"how many number"<<endl; cin>>n; int arr[n]; // added this cout<<"enter element"<<endl; for (i = 0;i<n;i++) { cin>>arr[i]; } for ( i =0;i<n;i++) { for ( j = 0;j<n;j++) { if (arr[i]<arr[j]) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } cout<<"after sorting "<<endl; //for clarity : for (i=0;i<n;i++) { //cout<<a[i]; wrong refference to arrary name. use arr instead of a cout<<arr[i]<<" "; } cout <<endl; //no need this, actually return 0; }
14th Oct 2021, 2:55 PM
Jayakrishna 🇮🇳