Untitled
unknown
plain_text
a year ago
1.3 kB
3
Indexable
#include <stdio.h> #include <stdlib.h> int main() { int numbers[20]; printf("Random Numbers in the range of -62 to -14:\n"); for (int i = 0; i < 20; i++) { numbers[i] = rand() % 49 - 62; printf("%d ", numbers[i]); } printf("\n"); int evenNumbers[20], oddNumbers[20]; int evenCount = 0, oddCount = 0; for (int i = 0; i < 20; i++) { if (numbers[i] % 2 == 0) { evenNumbers[evenCount++] = numbers[i]; } else { oddNumbers[oddCount++] = numbers[i]; } } sort(evenNumbers, evenCount); sort(oddNumbers, oddCount); printf("Even Numbers in Descending Order:\n"); for (int i = 0; i < evenCount; i++) { printf("%d ", evenNumbers[i]); } printf("\n"); printf("Odd Numbers in Descending Order:\n"); for (int i = 0; i < oddCount; i++) { printf("%d ", oddNumbers[i]); } printf("\n"); return 0; } void sort(int arr[], int n) { for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n - i - 1; j++) { if (arr[j] < arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } }