0

Hi !

I have arrray A[n][n] and i can input numbers in the interval -100 and 100 . I need to copy array A to array C[n*n] , and copy the number who are in a user iputed interval [k;l] and sort array C. I need help . I out put some big numbers and i dond know were i got it wrong.

```
int main(int argc, char *argv[])
{
int n , k , l ;
int i , j , z = 0 ;
int temp = 0;
cout << "Enter number of row and columns for 2d array A[N;N]:" ;
cin >> n ;
int a[n][n];
int c[n*n];
cout << "Enter interval [K;L] for the new array C "<< endl ;
cout << "K and L must be between -100 and 100"<< endl ;
do{
cout<<"K =";
cin>>k;
}
while( !( k >= -100 ) || !( k <= 100 ) );
do{
cout<<"L =";
cin>>l;
}
while( !( l > k ) || !( l <= 100 ) );
cout << "Enter A[N;N]"<< endl ;
for(i = 0; i < n; i++){
for(j = 0; j < n; j++){
do{
cout<<"A["<< i << "][" << j << "]:";
cin>>a[i][j];
}
while( !( a[i][j]>= -100 ) || !( a[i][j] <= 100 ) );
}
}
cout << "N is:" << n << endl;
cout << "K is:" << k << endl;
cout << "L is:" << l << endl << endl;
cout << "Array A:" << endl;
for(i = 0; i < n; i++){
for(j = 0; j < n; j++){
cout << a[i][j]<< " ";
}
cout << endl;
}
for(i = 0; i < n; ++i){
for(j = 0; j < n; ++j){
if(( a[i][j]>= k ) && ( a[i][j] <= l )){
c[z] = a[i][j] ;
z++;
}
}
}
for(i=0;i<(n*n);i++){
for(j=i+1;j<(n*n);j++){
if(c[i]>c[j]){
temp=c[i];
c[i]=c[j];
c[j]=temp;
}
}
}
cout << "Sorted array C:" << endl;
for(i = 0; i < (n*n); i++){
cout << c[i] << " ";
}
cout << endl;
system("PAUSE");
return EXIT_SUCCESS;
}
```