0
Where I m doing Mistake can anyone identify plz
2 Réponses
+ 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"
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;
}