Didn't know why my odd array is displaying some large number. I want to print only the odd numbers from the array in a sorted manner.
Like if the array is 1 4 6 8 0 9
Print only 1 9
selectionSort() is just the function that sorts the array.
int main()
{
int T, n, p, size,sum=0,si=0;
cin >> T;
for (int i = 0; i < T; i++)
{
cin >> n;
int a[n];
int odd[n];
for (int j = 0; j < n; j++)
{
cin >> a[j];
}
for (int j = 0; j < n; j++)
{
p = 0;
if (a[j] % 2 != 0){
odd[p++] = a[j];
si++;
}
}
selectionSort(odd, si);
What is wrong here in for loop?
for (int k = 0; k < si; k++)
{
cout << odd[k] << endl;
// sum += odd[j];
}
// cout << sum << endl;
sum = 0;
si=0;
}
return 0;
}
Output is :
1
4
1 5 7 9
9
16
4200276
6422112
Expecting
1
4
1 5 7 9
1
5
7
9