#include <stdio.h>
void sortOddEven(int arr[], int n);
int main() {
int n;
printf("Enter the number of elements in the array: ");
scanf("%d", &n);
int arr[n];
printf("Enter the elements of the array:\n");
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
sortOddEven(arr, n);
printf("Sorted array with odd numbers first and even numbers next:\n");
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
return 0;
}
void sortOddEven(int arr[], int n) {
int oddIndex = 0;
int evenIndex = n - 1;
while (oddIndex < evenIndex) {
while (arr[oddIndex] % 2 != 0) {
oddIndex++;
}
while (arr[evenIndex] % 2 == 0) {
evenIndex--;
}
if (oddIndex < evenIndex) {
int temp = arr[oddIndex];
arr[oddIndex] = arr[evenIndex];
arr[evenIndex] = temp;
}
}
}